Exemple #1
0
        public CommentsCountViewModel Execute(CommentsCountInputModel inputModel)
        {
            IDocumentCollection info;
            var spamCount = _database
                            .Statistics <Comment>(out info)
                            .Where(x => x.IsPotentialSpam)
                            .LongCount();


            var history = _database.Query <Comment>()
                          .Where(x => x.PublishedDate > DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0)))
                          .ToList()
                          .GroupBy(x => x.PublishedDate.Date)
                          .Select(x => new DateCountViewModal
            {
                PostedDate          = x.Key.ToString("MM/dd"),
                SpamCount           = x.Sum(a => a.IsPotentialSpam ? 1 : 0),
                PostedCommentsCount = x.Sum(a => a.IsApproved ? 1 : 0),
            });

            return(new CommentsCountViewModel
            {
                Total = info.Count,
                Spam = spamCount,
                History = history
            });
        }
        /// <summary>
        /// Gets the view for comments count.
        /// </summary>
        /// <returns></returns>
        public ActionResult Count(CommentsCountInputModel commentsCountInputModel)
        {
            if (!commentsCountInputModel.AllowComments.HasValue || commentsCountInputModel.AllowComments.Value)
            {
                var commentsCountViewModel = this.Model.GetCommentsCountViewModel(commentsCountInputModel);

                if (commentsCountViewModel != null)
                {
                    this.ViewBag.ServiceUrl = RouteHelper.ResolveUrl("~/RestApi/comments-api/", UrlResolveOptions.Rooted);
                    return(this.View(this.countTemplateName, commentsCountViewModel));
                }
            }

            return(new EmptyResult());
        }