public async Task<ActionResult> New(EditModel model) { if (string.IsNullOrWhiteSpace(model.Title) || string.IsNullOrWhiteSpace(model.Body) || string.IsNullOrWhiteSpace(model.Tags)) { ModelState.AddModelError("", "No field must be left blank."); return View(model); } var id = (await _postService.AddPost(model.Title, model.Body, model.Tags, User)).ToString(); return RedirectToAction("Edit", new { id = id, resultMessage = "The post has been published successfully." }); }
public async Task<ActionResult> Edit(EditModel model) { if (string.IsNullOrWhiteSpace(model.Title) || string.IsNullOrWhiteSpace(model.Body) || string.IsNullOrWhiteSpace(model.Tags) || string.IsNullOrWhiteSpace(model.Id)) { ModelState.AddModelError("", "All forms must not be empty."); return View(model); } await _postService.UpdatePost(model.Id, model.Title, model.Body, model.Tags); return RedirectToAction("Edit", new { id = model.Id, resultMessage = "The post has been edited successfully." }); }