public async Task <IActionResult> Edit(int id, CreateOrUpdateViewModel category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { category.Alias = category.Name.ToFriendlyUrl(); category.UpdateDate = DateTime.Now; var viewModel = _mapper.Map <Category>(category); _context.Update(viewModel); Alert("Lưu danh mục thành công!"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(nameof(CreateOrUpdate), category)); }
public async Task <IActionResult> Edit(int id, CreateOrUpdateBookViewModel book, IFormFile fImage) { if (id != book.Id) { return(NotFound()); } if (ModelState.IsValid) { if (string.IsNullOrEmpty(book.Image) && fImage.Length == 0) { ModelState.AddModelError("", "Uploaded file is empty or null."); DropdownForm(null); return(View(nameof(CreateOrUpdate), book)); } string image = UploadFileExtensions.UploadFile(fImage, "books"); if (!string.IsNullOrEmpty(image)) { book.Image = image; } book.Alias = book.Title.ToFriendlyUrl(); var viewModel = _mapper.Map <Book>(book); _context.Update(viewModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } DropdownForm(book); return(View(nameof(CreateOrUpdate), book)); }
public async Task <IActionResult> Edit(int id, CreateOrUpdateAuthorViewModel Author) { if (id != Author.Id) { return(NotFound()); } if (ModelState.IsValid) { Author.Alias = Author.Name.ToFriendlyUrl(); var viewModel = _mapper.Map <Author>(Author); _context.Update(viewModel); Alert("Lưu danh mục thành công!"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(nameof(CreateOrUpdate), Author)); }