public async Task <IActionResult> Create(FolderVm folder, string[] CategoryFolder, string[] TagFolder, List <IFormFile> Files) { if (ModelState.IsValid) { Folder model = _mapper.Map <Folder>(folder); AddCategories(model, CategoryFolder); AddTags(model, TagFolder); AddFiles(model, Files); _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ParentId"] = new SelectList(_context.Folder, "FolderId", "FolderId", folder.ParentId); return(View(folder)); }
// GET: Folders/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var folder = await _context.Folder.Include(f => f.Parent).Include(f => f.CategoryFolder).Include(f => f.TagFolder).FirstOrDefaultAsync(i => i.FolderId == id); FolderVm vm = _mapper.Map <FolderVm>(folder); if (folder == null) { return(NotFound()); } vm.SelectedCategories = folder.CategoryFolder.Select(e => e.CategoryId).AsEnumerable(); vm.SelectedTags = folder.TagFolder.Select(e => e.TagId).AsEnumerable(); ViewData["ParentId"] = new SelectList(_context.Folder, "FolderId", "Title", folder.ParentId); ViewData["SelectedCategories"] = new MultiSelectList(_context.Category.AsEnumerable(), "CategoryId", "Title", vm.CategoryFolder.Select(c => c.CategoryId)); ViewData["SelectedTags"] = new MultiSelectList(_context.Tag.AsEnumerable(), "TagId", "Title", vm.TagFolder.Select(c => c.TagId)); return(View(vm)); }
public async Task <IActionResult> Edit(int id, FolderVm folder, string[] SelectedCategories, string[] SelectedTags, List <IFormFile> Files) { if (id != folder.FolderId) { return(NotFound()); } RemoveCategories(id); RemoveFiles(id); RemoveTags(id); if (ModelState.IsValid) { try { Folder model = _mapper.Map <Folder>(folder); AddCategories(model, SelectedCategories); AddTags(model, SelectedTags); AddFiles(model, Files); _context.Update(model); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FolderExists(folder.FolderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ParentId"] = new SelectList(_context.Folder, "FolderId", "FolderId", folder.ParentId); return(View(folder)); }