public ActionResult CreateNewFolder(FolderModel model) { try { if (!ModelState.IsValid) { return RedirectToAction("Error", "Base", new { eID = 0 }); } var folder = new Folder { FolderName = model.FolderName, ParentID = model.ParentID, IsDeleted = 0, Description = model.Description, IsPublic = model.IsPublic, Keywords = model.Keywords, CreatedByUserID = int.Parse(User.Identity.Name), CreatedOnDate = DateTime.Now }; var parentFolder = _repository.FindFolderByID(folder.ParentID.Value); if (string.IsNullOrEmpty(parentFolder.Path)) { folder.Path = parentFolder.FolderName + @"\"; } else { folder.Path = parentFolder.Path + parentFolder.FolderName + @"\"; } string dir = _root + folder.Path + folder.FolderName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); _repository.AddFolder(folder); _repository.CommitChanges(); } else { return RedirectToAction("Error", new { eID = 4 }); } return RedirectToAction("ShowFolder", new { folderID = folder.ParentID }); } catch (Exception) { return RedirectToAction("Error", new {eID = 0}); } }
public ActionResult EditFolder(FolderModel model) { try { if (!ModelState.IsValid) { return RedirectToAction("Error", new { eID = 0 }); } var folder = _repository.FindFolderByID(model.FolderID); folder.Description = model.Description; folder.Keywords = model.Keywords; folder.LastModifiedOnDate = DateTime.Now; folder.LastModifiedByUserID = int.Parse(User.Identity.Name); if (folder.CreatedByUserID != folder.LastModifiedByUserID) { folder.IsPublic = 1; } else { folder.IsPublic = model.IsPublic; } var oldDir = _root + folder.Path + folder.FolderName; // Old directory var newDir = _root + folder.Path + model.FolderName; // New directory if (!oldDir.Equals(newDir)) { if (!Directory.Exists(newDir)) { Directory.Move(oldDir, newDir); folder.FolderName = model.FolderName; _repository.UpdateFolder(folder); _repository.CommitChanges(); } else { return RedirectToAction("Error", new { eID = 4 }); } } else { _repository.UpdateFolder(folder); _repository.CommitChanges(); } return RedirectToAction("ShowFolder", new { folderID = folder.ParentID }); } catch (Exception) { return RedirectToAction("Error", new {eID = 0}); } }
public PartialViewResult CreateNewFolder(int parentID) { var model = new FolderModel { ParentID = parentID }; return PartialView(model); }
public PartialViewResult EditFolder(int folderID) { var folder = _repository.FindFolderByID(folderID); var model = new FolderModel { FolderID = folder.ID, FolderName = folder.FolderName, Description = folder.Description, IsPublic = folder.IsPublic.Value, Keywords = folder.Keywords, CreateByUserID = folder.CreatedByUserID }; return PartialView(model); }