public ActionResult New(CreateCommentViewModel model) { PermissionSet permissions; Topic topic; using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { topic = _topicService.Get(model.Topic); var comment = new Post(); comment = _postService.AddNewPost(model.Context, topic, LoggedUser,out permissions); try { unitOfWork.Commit(); return RedirectToAction("Show", "Topic", new { id = topic.Id }); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); } } return View(); }
public Post AddNewPost(string postContent, Topic topic, User user, out PermissionSet permissions) { permissions = _roleService.GetPermissions(topic.Category, UsersRole(user)); if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked) { throw new ApplicationException(""); } var comment = new Post { PostContent = postContent, User = user, Topic = topic, IpAddress = StringUtils.GetUsersIpAddress(), PostType = PostType.comment.ToString(), DateCreated = DateTime.UtcNow, DateEdited = DateTime.UtcNow }; comment = SanitizePost(comment); Add(comment); return comment; }
public Topic AddLastPost(Topic topic, string postContent) { topic = SanitizeTopic(topic); var post = new Post { DateCreated = DateTime.UtcNow, DateEdited = DateTime.UtcNow, PostContent = StringUtils.GetSafeHtml(postContent), User = topic.User, Topic = topic, IpAddress = StringUtils.GetUsersIpAddress(), PostType = "topic" }; this._postRepository.Add(post); topic.Posts.Add(post); return topic; }
public void Delete(Post item) { this._context.Post.Remove(item); }
public Post Add(Post post) { return this._context.Post.Add(post); }
public void Update(Post item) { // Check there's not an object with same identifier already in context if (this._context.Post.Local.Select(x => x.Id == item.Id).Any()) { throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit"); } this._context.Entry(item).State = EntityState.Modified; }
public bool Delete(Post post) { return false; }
public Post Add(Post post) { return _postRepository.Add(post); }
public void SaveOrUpdate(Post post) { this._postRepository.Update(post); }
public Post SanitizePost(Post post) { post.PostContent = StringUtils.GetSafeHtml(post.PostContent); return post; }