public void UpdatePost(UpdatePostBindModel bindModel) { var post = _context.Posts.Find(bindModel.Id); if (post == null) { throw new Exception("Unable to find the post"); } if (post.IsDeleted) { throw new Exception("Unable to update a deleted post"); } bindModel.UpdatePost(post); _context.SaveChanges(); }
public IActionResult Edit(UpdatePostBindModel bindModel) { try { if (ModelState.IsValid) { _service.UpdatePost(bindModel); return(RedirectToAction(nameof(View), new { id = bindModel.Id })); } } catch (Exception) { ModelState.AddModelError(string.Empty, "An Error occured saving the post"); } return(View(bindModel)); }