public ActionResult Create([ModelBinder(typeof(CreateOrEditPostCustomDataBinder))] CreateOrEditPostModel model) { model.Post.UrlSlug = Slug.GenerateSlug(model.Post.Title); _postRepository.Add(model.Post); _blogRepository.AddPost(model.Blog.Id, model.Post); return(RedirectToAction("Details", "Blog")); }
public ActionResult Create([ModelBinder(typeof(CreateOrEditPostCustomDataBinder))] CreateOrEditPostModel model) { if (string.IsNullOrWhiteSpace(model.Post.Title)) { ModelState.AddModelError("Post.Title", "You must specify a title."); } if (string.IsNullOrWhiteSpace(model.Post.Content)) { ModelState.AddModelError("Post.Content", "You must specify a content."); } if (!ModelState.IsValid) { return(View()); } model.Post.UrlSlug = Slug.GenerateSlug(model.Post.Title); _postRepository.Add(model.Post); _blogRepository.AddPost(model.Blog.Id, model.Post); return(RedirectToAction("Details", "Blog")); }
public ActionResult Edit([ModelBinder(typeof(CreateOrEditPostCustomDataBinder))] CreateOrEditPostModel model) { _postRepository.Edit(model.Post); return(RedirectToAction("Details", "Blog")); }