Ejemplo n.º 1
0
        public async Task <CommentDefaultViewModel> GetAllComments()
        {
            var comments = await _unitOfWork.Repository <Comment>().Query()
                           .Include(x => x.User)
                           .Include(c => c.Post)
                           .Select(x => new CommentViewModel
            {
                User    = _mapper.Map <User, UserViewModel>(x.User),
                Post    = x.Post,
                Comment = _mapper.Map <Comment, CommentDto>(x),
            })
                           .ToListAsync();

            var viewModel = new CommentDefaultViewModel
            {
                AllComments              = comments,
                NumberOfComments         = comments.Count(),
                ApprovedComments         = GetCommentsByStatus(comments, CommentStatus.Approved),
                NumberOfApprovedComments = CountComment(comments, CommentStatus.Approved),
                PendingComments          = GetCommentsByStatus(comments, CommentStatus.Pending),
                NumberOfPendingComments  = CountComment(comments, CommentStatus.Pending),
                SpamComments             = GetCommentsByStatus(comments, CommentStatus.Spam),
                NumberOfSpamComments     = CountComment(comments, CommentStatus.Spam),
                DeletedComments          = GetCommentsByStatus(comments, CommentStatus.Trash),
                NumberOfDeletedComments  = CountComment(comments, CommentStatus.Trash)
            };

            return(viewModel);
        }
Ejemplo n.º 2
0
        public async Task <CommentDefaultViewModel> GetAllComments()
        {
            var comments = _unitOfWork.Repository <Comment>().Query();

            var viewModel = new CommentDefaultViewModel
            {
                AllComments              = await comments.ToListAsync(),
                NumberOfComments         = comments.Count(),
                ApprovedComments         = await GetCommentsByStatus(comments, CommentStatus.Approved).ConfigureAwait(false),
                NumberOfApprovedComments = CountComment(comments, CommentStatus.Approved),
                PendingComments          = await GetCommentsByStatus(comments, CommentStatus.Pending).ConfigureAwait(false),
                NumberOfPendingComments  = CountComment(comments, CommentStatus.Pending),
                SpamComments             = await GetCommentsByStatus(comments, CommentStatus.Spam).ConfigureAwait(false),
                NumberOfSpamComments     = CountComment(comments, CommentStatus.Spam),
                DeletedComments          = await GetCommentsByStatus(comments, CommentStatus.Trash).ConfigureAwait(false),
                NumberOfDeletedComments  = CountComment(comments, CommentStatus.Trash)
            };

            return(viewModel);
        }