Exemple #1
0
        public async Task <IEnumerable <ArticleProjection> > Handle(AllArticles request, CancellationToken cancellationToken)
        {
            var client           = _clientFactory.Create();
            var allArticlesAsync = Task.Run(
                () => client.GetAllAsync(new Empty()).ResponseAsync, cancellationToken);
            var tagsView = await _mediator.Send(new AllTags(), cancellationToken);

            var articles = await allArticlesAsync;

            var result = new List <ArticleProjection>();

            foreach (var article in articles.Items)
            {
                var articleTags = tagsView.Tags
                                  .Where(t => t.ArticleIds.Contains(article.Id))
                                  .Select(t => t.Name)
                                  .ToArray();

                var projection = new ArticleProjection
                {
                    Id           = Guid.Parse(article.Id),
                    Title        = article.Title,
                    Description  = article.Description,
                    Body         = article.Body,
                    Slug         = article.Slug,
                    CreatedAtUtc = article.CreatedAtUtc.ToDateTimeOffset(),
                    UpdatedAtUtc = article.UpdatedAtUtc.ToDateTimeOffset(),
                    TagList      = articleTags
                };

                result.Add(projection);
            }

            return(result);
        }
        //
        // GET: /TestPager/

        public ActionResult Index(string title, string author, string source, int id = 1)
        {
            var qry = AllArticles.AsQueryable();

            if (!string.IsNullOrWhiteSpace(title))
            {
                qry = qry.Where(a => a.Title.Contains(title));
            }
            if (!string.IsNullOrWhiteSpace(author))
            {
                qry = qry.Where(a => a.Author.Contains(author));
            }
            if (!string.IsNullOrWhiteSpace(source))
            {
                qry = qry.Where(a => a.Source.Contains(source));
            }
            var model = qry.OrderByDescending(a => a.PubDate).ToPagedList(id, 5);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("ArticleListPartial", model));
            }


            return(View(model));
        }
        public ActionResult Search(int id = 1, string kword = null)
        {
            var query = AllArticles.AsQueryable();

            if (!string.IsNullOrWhiteSpace(kword))
            {
                query = query.Where(a => a.Title.Contains(kword));
            }
            var model = query.OrderByDescending(a => a.PubDate).ToPagedList(id, 5);

            return(View(model));
        }
Exemple #4
0
 public Article GetArticleById(int articleId)
 {
     return(AllArticles.FirstOrDefault(p => p.ArticleId == articleId));
 }