private static void valid_comment_submission(BlogPostCommentViewModel inModel, BlogPostViewModel result) { // TODO: have attributes on the viewmodel and do validation elsewhere if (inModel.UserDisplayName.IsEmpty()) { result.AddInvalidField <BlogPostCommentViewModel>(x => x.UserDisplayName); } if (inModel.UserEmail.IsEmpty()) { result.AddInvalidField <BlogPostCommentViewModel>(x => x.UserEmail); } if (inModel.Body.IsEmpty()) { result.AddInvalidField <BlogPostCommentViewModel>(x => x.Body); } }
public BlogPostViewModel Comment(BlogPostCommentViewModel inModel) { var badRedirectResult = new BlogPostViewModel { ResultOverride = new RedirectResult(_resolver.PageNotFoundUrl()) }; if (inModel.Slug.IsEmpty()) { return(badRedirectResult); } var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault(); if (post == null) { return(badRedirectResult); } var result = new BlogPostViewModel(); valid_comment_submission(inModel, result); if (result.InvalidFields.Count > 0) { result.ResultOverride = new RedirectResult(_resolver.PublishedPost(new PostDisplay(post))); return(result); } var user = _userService.AddOrUpdateUser(inModel.UserEmail, inModel.UserDisplayName, inModel.UserUrl); _blogPostCommentService.AddCommentToBlogPost(inModel.Body, inModel.UserSubscribed, user, post); var postDisplay = new PostDisplay(post); result.ResultOverride = new RedirectResult(_resolver.PublishedPost(postDisplay)); return(result); }