Exemplo n.º 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();
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 4
0
 public void Delete(Post item)
 {
     this._context.Post.Remove(item);
 }
Exemplo n.º 5
0
 public Post Add(Post post)
 {
     return this._context.Post.Add(post);
 }
Exemplo n.º 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;
 }
Exemplo n.º 7
0
 public bool Delete(Post post)
 {
     return false;
 }
Exemplo n.º 8
0
 public Post Add(Post post)
 {
     return _postRepository.Add(post);
 }
Exemplo n.º 9
0
 public void SaveOrUpdate(Post post)
 {
     this._postRepository.Update(post);
 }
Exemplo n.º 10
0
 public Post SanitizePost(Post post)
 {
     post.PostContent = StringUtils.GetSafeHtml(post.PostContent);
     return post;
 }