public ActionResult RemoveComment(Comment model)
        {
            var comment = context.Comments.Find(model.Id);
            var status = context.Status.Find(comment.Status.Id);

            if (currentUser.CanDelete(comment))
            {
                context.Comments.Remove(comment);
                context.SaveChanges();
            }

            var comments = CommentsByStatus(status);

            ModelState.Clear();
            return PartialView("CommentsPartial", comments);
        }
        public ActionResult AddComment(int id, string text)
        {
            var status = context.Status.Find(id);
            Comment comment = new Comment
            {
                Status = status,
                Author = currentUser,
                DateTime = DateTime.Now,
                Text = text,
                IsDeletable = true,
                IsUpdatable = true
            };

            if (currentUser.CanCreate(comment))
            {
                context.Comments.Add(comment);
                context.SaveChanges();
            }

            ModelState.Clear();
            return PartialView("CommentPartial", comment);
        }
        public ActionResult UpdateComment(Comment model)
        {
            var comment = context.Comments.Find(model.Id);

            if (currentUser.CanUpdate(comment))
            {
                comment.Text = model.Text;

                context.SaveChanges();
            }

            var comments = CommentsByStatus(comment.Status);

            ModelState.Clear();
            return PartialView("CommentsPartial", comments);
        }
Exemple #4
0
 public bool CanUpdate(Comment comment)
 {
     return Id == comment.Author.Id;
 }
Exemple #5
0
 public bool CanDelete(Comment comment)
 {
     return Id == comment.Author.Id || Id == comment.Status.Author.Id;
 }
Exemple #6
0
 public bool CanCreate(Comment comment)
 {
     return Id == comment.Status.Author.Id || Friends.Any(f => f.Id == comment.Status.Author.Id);
 }