예제 #1
0
        public ArticlesCountViewModel Execute(ArticlesCountInputModel inputModel)
        {
            IDocumentCollection stats;
            var draftCount = _database
                             .Statistics <Article>(out stats)
                             .Where(x => !x.IsPublished)
                             .LongCount();

            var history = _database.Query <Article>()
                          .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"),
                DraftArticleCount  = x.Sum(a => a.IsPublished ? 0 : 1),
                PostedArticleCount = x.Sum(a => a.IsPublished ? 1 : 0),
            });

            return(new ArticlesCountViewModel
            {
                Total = stats.Count,
                Draft = draftCount,
                History = history
            });
        }
예제 #2
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
            });
        }
예제 #3
0
        public ArticleViewModel Execute(ArticleInputModel inputModel)
        {
            var article = _database.Query <Article>().FirstOrDefault(x => x.Id == inputModel.Uri);

            if (article == null)
            {
                return(new ArticleViewModel());
            }

            var user = _database.Query <User>().SingleOrDefault(u => u.Id == article.AuthorId);

            var model = article.DynamicMap <ArticleViewModel>();

            model.Author = user.FullName();

            return(model);
        }
예제 #4
0
        public BasicInformationViewModel Execute(BasicInformationInputModel inputModel)
        {
            var user = _database.Query <User>()
                       .SingleOrDefault(x => x.Id == _securityContext.CurrentIdentity.Name) ??
                       new User();

            return(user.DynamicMap <BasicInformationViewModel>());
        }
예제 #5
0
        public RecentDraftsViewModel Execute(RecentDraftsInputModel inputModel)
        {
            var articles = _database.Query <Article>()
                           .OrderByDescending(x => x.PublishedDate)
                           .Where(x => !x.IsPublished)
                           .Take(5);

            return(new RecentDraftsViewModel(articles.Select(x => x.DynamicMap <RecentDraftViewModel>())));
        }
예제 #6
0
        public AuthorsViewModel Execute(AuthorsInputModel inputModel)
        {
            var authors = _database.Query <User>().ToList();

            return(new AuthorsViewModel
            {
                Authors = authors.Select(x => x.DynamicMap <AuthorViewModel>())
            });
        }
예제 #7
0
        public IEnumerable <RecentCommentViewModel> Execute(RecentCommentInputModel inputModel)
        {
            var recentComments = _database
                                 .Query <Comment>()
                                 .OrderByDescending(x => x.PublishedDate)
                                 .Take(5);

            return(recentComments.Select(x => x.DynamicMap <RecentCommentViewModel>()));
        }
예제 #8
0
        public DeleteArticleViewModel Execute(DeleteArticleInputModel inputModel)
        {
            _database.Delete <Article>(inputModel.Id);

            _database.Query <Comment>()
            .Where(x => x.ArticleUri == inputModel.Id)
            .Each(x => _database.Delete(x));

            return(new DeleteArticleViewModel());
        }
예제 #9
0
        public ComposeViewModel Execute(ComposeInputModel inputModel)
        {
            if (string.IsNullOrEmpty(inputModel.Id))
            {
                return(new ComposeViewModel());
            }

            var article = _database.Query <Article>()
                          .First(x => x.Id == inputModel.Id);

            return(article.DynamicMap <ComposeViewModel>());
        }
예제 #10
0
        public ArchiveViewModel Execute(ArchiveInputModel inputModel)
        {
            var articles = _database.Query <Article>()
                           .Where(x => x.IsPublished)
                           .ToList();

            return(new ArchiveViewModel
            {
                Items = articles
                        .GroupBy(x => x.PublishedDate.Year, x => x.DynamicMap <ArchiveItemViewModel>())
                        .ToDictionary(x => x.Key, x => x.ToList())
            });
        }
예제 #11
0
        public DeleteCommentViewModel Execute(DeleteCommentInputModel inputModel)
        {
            var comment = _database.Query <Comment>()
                          .FirstOrDefault(x => x.Id == inputModel.Id);

            if (comment != null)
            {
                _database.Decrement <Article>(comment.ArticleUri, x => x.CommentsCount);
                _database.Delete(comment);
            }

            return(new DeleteCommentViewModel());
        }
예제 #12
0
        public ArticleSummariesViewModel Execute(ArticleSummariesInputModel inputModel)
        {
            var articles = _database.Query <Article>()
                           .Where(x => x.IsPublished)
                           .OrderByDescending(x => x.PublishedDate)
                           .Take(10).ToList();

            var summaries = articles.Select(a =>
            {
                //TODO: improve
                var user = _database.Query <User>().SingleOrDefault(u => u.Id == a.AuthorId);

                var article = a.DynamicMap <ArticleSummaryViewModel>();

                article.Author = user.FullName();
                return(article);
            });

            return(new ArticleSummariesViewModel
            {
                Summaries = summaries
            });
        }
예제 #13
0
        public CommentsViewModel Execute(CommentsInputModel inputModel)
        {
            var comments = _database
                           .Query <Comment>()
                           .Where(x => x.ArticleUri.Equals(inputModel.Uri))
                           .OrderByDescending(x => x.PublishedDate)
                           .ToList();

            return(new CommentsViewModel
            {
                Uri = inputModel.Uri,
                Comments = comments.Select(x => x.DynamicMap <CommentViewModel>())
            });
        }
예제 #14
0
        public ManageCommentsViewModel Execute(ManageCommentsInputModel inputModel)
        {
            long totalCount;

            var comments = _database
                           .Query <Comment>()
                           // .WithCount<Comment>(out totalCount)
                           //.AsQueryable<Comment>()
                           .FilteryBySpam(inputModel.ShowSpam)
                           .OrderByDescending(x => x.PublishedDate)
                           .Page(inputModel)
                           .ToList();

            return(new ManageCommentsViewModel
            {
                Comments = comments.Select(x => x.DynamicMap <ManageCommentViewModel>()),
                //TotalPages = totalCount.TotalPages(inputModel.Count),
                ShowSpam = inputModel.ShowSpam
            });
        }