예제 #1
0
        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();
        }
예제 #2
0
파일: PostService.cs 프로젝트: h2h/CandyBBS
        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;
        }
예제 #3
0
        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;
        }
예제 #4
0
 public void Delete(Post item)
 {
     this._context.Post.Remove(item);
 }
예제 #5
0
 public Post Add(Post post)
 {
     return this._context.Post.Add(post);
 }
예제 #6
0
 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;
 }
예제 #7
0
파일: PostService.cs 프로젝트: h2h/CandyBBS
 public bool Delete(Post post)
 {
     return false;
 }
예제 #8
0
파일: PostService.cs 프로젝트: h2h/CandyBBS
 public Post Add(Post post)
 {
     return _postRepository.Add(post);
 }
예제 #9
0
파일: PostService.cs 프로젝트: h2h/CandyBBS
 public void SaveOrUpdate(Post post)
 {
     this._postRepository.Update(post);
 }
예제 #10
0
파일: PostService.cs 프로젝트: h2h/CandyBBS
 public Post SanitizePost(Post post)
 {
     post.PostContent = StringUtils.GetSafeHtml(post.PostContent);
     return post;
 }