public int CreatePost(CreatePostBindModel bindModel) { var post = bindModel.ToPost(); _context.Add(post); _context.SaveChanges(); return(post.PostId); }
public IActionResult Create(CreatePostBindModel bindModel) { try { if (ModelState.IsValid) { int id = _service.CreatePost(bindModel); return(RedirectToAction(nameof(View), new { id = id })); } } catch (Exception) { ModelState.AddModelError(string.Empty, "An Error occured saving the post"); } return(View(bindModel)); }