コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: User.cs プロジェクト: Booska14/MySocialNetwork
 public bool CanUpdate(Comment comment)
 {
     return Id == comment.Author.Id;
 }
コード例 #5
0
ファイル: User.cs プロジェクト: Booska14/MySocialNetwork
 public bool CanDelete(Comment comment)
 {
     return Id == comment.Author.Id || Id == comment.Status.Author.Id;
 }
コード例 #6
0
ファイル: User.cs プロジェクト: Booska14/MySocialNetwork
 public bool CanCreate(Comment comment)
 {
     return Id == comment.Status.Author.Id || Friends.Any(f => f.Id == comment.Status.Author.Id);
 }