Exemplo n.º 1
0
        public ActionResult ManageComments([DefaultValue(1)] int page, string type)
        {
            var userId           = GetUserId();
            var status           = type != null ? (int)Enum.Parse(typeof(CommentStatus), type, true) : int.MaxValue;
            var posts            = _postRepository.GetPostsByUserID(userId);
            var filteredComments = _commentRepository.GetAllComments()
                                   .Where(c => posts.Select(p => p.PostID)
                                          .Contains(c.PostID))
                                   .ToList();
            var commentsByType = status == int.MaxValue ? filteredComments : filteredComments.Where(c => c.CommentStatus == status).ToList();
            var commentModel   = new AdminCommentViewModel
            {
                Comments = commentsByType.Skip((page - 1) * _itemsPerPage)
                           .Take(_itemsPerPage)
                           .ToList()
                           .GetCommentLinks(posts, status),
                PagingInfo = new PagingInformation
                {
                    CurrentPage  = page,
                    ItemsPerPage = _itemsPerPage,
                    TotalItems   = commentsByType.Count()
                },
                Type                  = type,
                AllCommentsCount      = filteredComments.Count(),
                ApprovedCommentsCount = filteredComments.Count(c => c.CommentStatus == 0),
                PendingCommentsCount  = filteredComments.Count(c => c.CommentStatus == 1),
                SpamCommentsCount     = filteredComments.Count(c => c.CommentStatus == 2),
                TrashCommentsCount    = filteredComments.Count(c => c.CommentStatus == -1),
                OneTimeCode           = GetToken(),
                Title                 = SettingsRepository.BlogName
            };

            return(View(commentModel));
        }
        public ActionResult Comments_Destroy([DataSourceRequest] DataSourceRequest request, AdminCommentViewModel comment)
        {
            if (this.ModelState.IsValid)
            {
                this.comments.Delete(comment.Id);
            }

            return(this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)));
        }
        public ActionResult Comments_Update([DataSourceRequest] DataSourceRequest request, AdminCommentViewModel comment)
        {
            if (this.ModelState.IsValid)
            {
                var entity = this.comments.GetById(comment.Id);

                entity.Content = comment.Content;
                this.comments.Save();
            }

            return(this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)));
        }