コード例 #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 Approve(SuggestionModel model, string commentText)
        {
            using (var container = new SuggestionBoxContainer())
            {
                var suggestion = container.Suggestions.FirstOrDefault(s => s.Id == model.Id);

                if (UserIsAdmin)
                {
                    var comment = new Comment
                                    {
                                        Body = commentText,
                                        Date = DateTime.Now,
                                        Status = (int)CommentStatus.Active
                                    };
                    suggestion.Comments.Add(comment);
                    suggestion.Status = (int)SuggestionStatus.Approved;

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

                return PartialView("Partials/_View", ConvertSuggestionToModel(suggestion));
            }
        }
コード例 #3
0
 /// <summary>
 /// Create a new Comment object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="body">Initial value of the Body property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="suggestionId">Initial value of the SuggestionId property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Comment CreateComment(global::System.Int32 id, global::System.String body, global::System.DateTime date, global::System.Int32 suggestionId, global::System.Int32 status)
 {
     Comment comment = new Comment();
     comment.Id = id;
     comment.Body = body;
     comment.Date = date;
     comment.SuggestionId = suggestionId;
     comment.Status = status;
     return comment;
 }
コード例 #4
0
        private CommentModel ConvertCommentToModel(Comment comment)
        {
            var model = Mapper.Map<Comment, CommentModel>(comment);
            model.CanBeDeleted = UserIsAdmin && model.Status != CommentStatus.Deleted;
            model.CanBeUndeleted = UserIsAdmin && model.Status == CommentStatus.Deleted;

            return model;
        }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Comments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToComments(Comment comment)
 {
     base.AddObject("Comments", comment);
 }