public ActionResult ModeratePost(ModerateActionViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var post = _postService.Get(viewModel.PostId); if (viewModel.IsApproved) { post.Pending = false; } else { _postService.Delete(post); } unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); return Content("error"); } } return Content("allgood"); }
public ActionResult ModerateTopic(ModerateActionViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var topic = _topicService.Get(viewModel.TopicId); var postIdList = new List<Guid>(); if (viewModel.IsApproved) { topic.Pending = false; } else { var postId = topic.LastPost.Id; var post = _postService.Get(postId); var deleteTopic = _postService.Delete(post); unitOfWork.SaveChanges(); if (deleteTopic) { postIdList = topic.Posts.Select(x => x.Id).ToList(); _topicService.Delete(topic); } } // We use temp data because we are doing a redirect //TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel //{ // Message = "Category Created", // MessageType = // GenericMessages.success //}; unitOfWork.Commit(); // Delete the topic posts if if (_luceneService.CheckIndexExists() && !viewModel.IsApproved) { foreach (var guid in postIdList) { _luceneService.Delete(guid); } } } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); return Content("error"); } } return Content("allgood"); }
public ActionResult ModerateTopic(ModerateActionViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var topic = _topicService.Get(viewModel.TopicId); if (viewModel.IsApproved) { topic.Pending = false; } else { var postId = topic.LastPost.Id; var post = _postService.Get(postId); var deleteTopic = _postService.Delete(post); unitOfWork.SaveChanges(); if (deleteTopic) { _topicService.Delete(topic); } } unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); return Content("error"); } } return Content("allgood"); }