public async Task <IActionResult> Edit(PostEditViewModel viewModel) { if (ModelState.IsValid) { Post post = await _context.Posts.FindAsync(viewModel.Id); if (post == null) { return(NotFound()); } post.Title = viewModel.Title; post.Content = viewModel.Content; post.Catalog = await _context.Catalog.FindAsync(viewModel.Catalog); _context.Update(post); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task <IActionResult> Edit(Catalog catalog) { if (ModelState.IsValid) { try { _context.Update(catalog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CatalogExists(catalog.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(catalog)); }