コード例 #1
0
        public ActionResult Add(CommentModel model)
        {
            var comment = new Comment
            {
                Body = model.Body,
                Date = DateTime.Now,
                SuggestionId = model.SuggestionId,
                Status = (int)CommentStatus.Active
            };

            using (var container = new SuggestionBoxContainer())
            {
                var suggestion = container.Suggestions.FirstOrDefault(s => s.Id == model.SuggestionId);
                suggestion.Comments.Add(comment);
                container.SaveChanges();
                container.AcceptAllChanges();

                var comments = suggestion.Comments
                    .Where(c => c.Status != (int)CommentStatus.Deleted || UserIsAdmin)
                    .OrderBy(c => c.Date).ToList();

                return PartialView("Partials/_CommentList",
                                   comments.Select(ConvertCommentToModel).ToList());
            }
        }
コード例 #2
0
        public ActionResult Delete(CommentModel model)
        {
            using (var container = new SuggestionBoxContainer())
            {
                var comment = container.Comments.FirstOrDefault(c => c.Id == model.Id);

                if (UserIsAdmin)
                {
                    comment.Status = (int)CommentStatus.Deleted;

                    container.SaveChanges();
                    container.AcceptAllChanges();
                }

                var comments = comment.Suggestion.Comments
                    .Where(c => c.Status != (int)CommentStatus.Deleted || UserIsAdmin)
                    .OrderBy(c => c.Date)
                    .Select(ConvertCommentToModel).ToList();

                return PartialView("Partials/_CommentList", comments);
            }
        }
コード例 #3
0
        private CommentModel SetupComment(CommentModel model)
        {
            model.CanBeDeleted = UserIsAdmin && model.Status != CommentStatus.Deleted;
            model.CanBeUndeleted = UserIsAdmin && model.Status == CommentStatus.Deleted;

            return model;
        }