public ActionResult CreatePost(CreateAjaxPostViewModel post) { PermissionSet permissions; Post newPost; Topic topic; using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id); // Check stop words var stopWords = _bannedWordService.GetAll(true); foreach (var stopWord in stopWords) { if (post.PostContent.IndexOf(stopWord.Word, StringComparison.CurrentCultureIgnoreCase) >= 0) { throw new Exception(LocalizationService.GetResourceString("StopWord.Error")); } } // Quick check to see if user is locked out, when logged in if (loggedOnUser.IsLockedOut || !loggedOnUser.IsApproved) { FormsAuthentication.SignOut(); throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess")); } topic = _topicService.Get(post.Topic); var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent); var akismetHelper = new AkismetHelper(SettingsService); newPost = _postService.AddNewPost(postContent, topic, loggedOnUser, out permissions); // Set the reply to newPost.InReplyTo = post.InReplyTo; if (akismetHelper.IsSpam(newPost)) { newPost.Pending = true; } try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } //Check for moderation if (newPost.Pending == true) { return PartialView("_PostModeration"); } // All good send the notifications and send the post back using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { // Create the view model var viewModel = ViewModelMapping.CreatePostViewModel(newPost, new List<Vote>(), permissions, topic, LoggedOnReadOnlyUser, SettingsService.GetSettings(), new List<Favourite>()); // Success send any notifications NotifyNewTopics(topic, unitOfWork); // Return view return PartialView("_Post", viewModel); } }
public ActionResult CreatePost(CreateAjaxPostViewModel post) { PermissionSet permissions; Post newPost; Topic topic; using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { // Quick check to see if user is locked out, when logged in if (LoggedOnUser.IsLockedOut | !LoggedOnUser.IsApproved) { FormsAuthentication.SignOut(); throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess")); } topic = _topicService.Get(post.Topic); var postContent = _bannedWordService.SanitiseBannedWords(post.PostContent); var akismetHelper = new AkismetHelper(SettingsService); newPost = _postService.AddNewPost(postContent, topic, LoggedOnUser, out permissions); if(!akismetHelper.IsSpam(newPost)) { try { unitOfWork.Commit(); // Successful, add this post to the Lucene index if (_luceneService.CheckIndexExists()) { _luceneService.AddUpdate(_luceneService.MapToModel(newPost)); } } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } else { unitOfWork.Rollback(); throw new Exception(LocalizationService.GetResourceString("Errors.PossibleSpam")); } } //Check for moderation if (newPost.Pending == true) { return PartialView("_PostModeration"); } else { // All good send the notifications and send the post back using (UnitOfWorkManager.NewUnitOfWork()) { // Create the view model var viewModel = new ViewPostViewModel { Permissions = permissions, Post = newPost, User = LoggedOnUser, ParentTopic = topic }; // Success send any notifications NotifyNewTopics(topic); return PartialView("_Post", viewModel); } } }