public ActionResult AddPost() { if (!Request.IsAuthenticated) throw new BusinessLogicException("Нельзя постить в блог будучи неаутентифицированным"); var model = new UserAddPostViewModel { AuthorName = UserContext.Current.DisplayName, AuthorId = UserContext.Current.Id }; return View(model); }
public ActionResult AddPost(UserAddPostViewModel model) { if (!Request.IsAuthenticated) throw new BusinessLogicException("Нельзя постить в блог будучи неаутентифицированным"); if (!ModelState.IsValid) return View(model); if (UserContext.Current.Id != model.AuthorId) throw new BusinessLogicException("Вы не можете постить в данный блог, т.к. не являетесь его владельцем"); ContentService.CreatePost(null, model.AuthorId, model.Title, model.Text, model.TagTitles, model.IsDraft, true); return RedirectToAction(model.IsDraft ? "drafts" : "index"); }