Skip to content

Commit

Permalink
replace storage of js files #9
Browse files Browse the repository at this point in the history
  • Loading branch information
geofranzi committed Nov 18, 2019
1 parent cfef5a1 commit ffe2aae
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Controllers/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,33 @@ public ActionResult Save(EventModel model, HttpPostedFileBase file)

private Event SaveFile(HttpPostedFileBase file, Event e, EventManager eManager)
{
BExIS.IO.FileHelper.CreateDicrectoriesIfNotExist(Server.MapPath("~/Areas/FMT/Scripts/Uploaded/" + e.Id + "/"));
string filename = "ext.js";
string path = Path.Combine(AppConfiguration.DataPath, "MetadataStructures", e.MetadataStructure.Id.ToString(), filename);

if (System.IO.File.Exists(Server.MapPath("~" + e.JavaScriptPath)) && file != null && file.ContentLength > 0)


if (System.IO.File.Exists(path) && file != null && file.ContentLength > 0)
{
var deletedFilePath = Path.Combine(AppConfiguration.DataPath, "EMM\\Deleted JS Files");
BExIS.IO.FileHelper.CreateDicrectoriesIfNotExist(deletedFilePath);

string filePath = Server.MapPath("~" + e.JavaScriptPath);
var des = deletedFilePath + "\\" + Path.GetFileName(filePath);
var des = deletedFilePath + "\\" + Path.GetFileName(path);

// Check if file already exists in the "Deleted Files" folder and rename the file if yes.
if (System.IO.File.Exists(des))
{
des = deletedFilePath + "\\" + new Random().Next(1, 1000) + "_" + Path.GetFileName(filePath);
des = deletedFilePath + "\\" + new Random().Next(1, 1000) + "_" + Path.GetFileName(path);
}

System.IO.File.Move(filePath, des);
System.IO.File.Move(path, des);
}

if (file != null && file.ContentLength > 0)
{
try
{
string path_save = Path.Combine(Server.MapPath("~/Areas/FMT/Scripts/Uploaded/" + e.Id + "/"), Path.GetFileName(file.FileName));

file.SaveAs(path_save);
e.JavaScriptPath = Path.Combine("/Areas/FMT/Scripts/Uploaded/" + e.Id + "/", Path.GetFileName(file.FileName));
file.SaveAs(path);
e.JavaScriptPath = path;
}
catch { }
}
Expand Down

0 comments on commit ffe2aae

Please sign in to comment.