public IActionResult Add([FromForm] EditFolderModel model) { var selectedFolder = _db.CajFolder.FirstOrDefault(x => x.Id == model.CurrentFolderId); CajFolder folder = null; if (selectedFolder != null) { //editing folder if (model.DestinationFolderId.HasValue) { folder = _db.CajFolder.FirstOrDefault(x => x.Id == model.DestinationFolderId.Value); if (folder != null) { folder.Name = model.Name; _db.CajFolder.Update(folder); _db.SaveChanges(); } } else { folder = new CajFolder() { Id = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, Name = model.Name, ParentId = model.CurrentFolderId }; _db.CajFolder.Add(folder); _db.SaveChanges(); } } return(Ok(folder != null ? new ObjectsModel(folder) : null)); }
public IActionResult CreateFolder(EditFolderModel model) { var parentPath = ""; var folder = new MediaFolder(); folder.Title = model.Title; if (model.parentFolderId.HasValue) { var parentFolder = _dataContext.Folders.FirstOrDefault(f => f.Id == model.parentFolderId); folder.ParentFolder = parentFolder; parentFolder.Items.Add(folder); parentPath = _galleryContext.GetFolderPath(model.parentFolderId.Value, null); } _dataContext.Items.Add(folder); _dataContext.SaveChanges(); var path = Path.Combine(_host.WebRootPath, "gallery", parentPath, folder.Title); Directory.CreateDirectory(path); return(RedirectToAction("Details", new { id = folder.Id })); }
public IActionResult CreateFolder(int?parentFolder) { var model = new EditFolderModel(); model.parentFolderId = parentFolder; return(View(model)); }
public IActionResult CreateFolder(EditFolderModel model, [FromServices] CreateFolderCommand createFolderCommand) { var messages = createFolderCommand.Validate(model); if (messages.Count > 0) { ModelState.AddModelError("_FORM", messages[0]); return(View(model)); } createFolderCommand.Execute(model); return(Redirect(Url.Content("~/"))); }
public IActionResult CreateFolder(EditFolderModel model) { var folder = new MediaFolder(); folder.Title = model.Title; if (model.parentFolderId.HasValue) { var parentFolder = _dataContext.Folders.FirstOrDefault(f => f.Id == model.parentFolderId); folder.ParentFolder = parentFolder; parentFolder.Items.Add(folder); } _dataContext.Items.Add(folder); _dataContext.SaveChanges(); return(RedirectToAction("Details", new { id = folder.Id })); }
public IActionResult CreateFolder(IList <IFormFile> files, int?parentFolder, [FromServices] SaveFolderCommand saveFolderCommand) { var list = new List <string>(); foreach (var file in files) { var model = new EditFolderModel(); model.Title = Path.GetFileName(file.FileName); model.parentFolderId = parentFolder; model.Folder = file; list.AddRange(saveFolderCommand.Validate(model)); saveFolderCommand.Execute(model); } ViewBag.Messages = list; return(View()); }