Esempio n. 1
0
        public async Task <IEnumerable <IPostSummary> > GetPostSummaries(IPostFilter postFilter)
        {
            var allPostMetadata = await _postSummaryRepository.GetPostSummaries();

            var query = allPostMetadata.AsQueryable();

            var filterTag = postFilter.Tag;

            if (!string.IsNullOrWhiteSpace(filterTag))
            {
                query = query.Where(x => x.Tags.Contains(filterTag, StringComparer.InvariantCultureIgnoreCase));
            }

            var filterAuthor = postFilter.Author;

            if (!string.IsNullOrWhiteSpace(filterAuthor))
            {
                query = query.Where(x => x.Author.Equals(filterAuthor, StringComparison.InvariantCultureIgnoreCase));
            }

            var filterYear = postFilter.Year;

            if (filterYear.HasValue)
            {
                query = query.Where(x => x.PublishedOn.Year == filterYear.Value);
            }

            var filterMonth = postFilter.Month;

            if (filterMonth.HasValue)
            {
                query = query.Where(x => x.PublishedOn.Month == filterMonth.Value);
            }

            var filterLanguageCode = postFilter.LanguageCode;

            if (!string.IsNullOrWhiteSpace(filterLanguageCode))
            {
                query = query.Where(x => x.LanguageCode.Equals(filterLanguageCode, StringComparison.InvariantCultureIgnoreCase));
            }

            var filterIncludesDraft = postFilter.IncludesDraft;

            query = query.Where(x => x.IsDraft == filterIncludesDraft);

            var postSummaries = query.ToList();

            return(postSummaries);
        }
Esempio n. 2
0
        public async Task <IEnumerable <IPostSummary> > GetPostSummaries()
        {
            var isEmpty = !_postSummaries.Any();

            if (isEmpty)
            {
                var postSummaries = await _postSummaryRepository.GetPostSummaries();

                foreach (var postSummary in postSummaries)
                {
                    _postSummaries.Add(postSummary);
                }
            }

            return(_postSummaries);
        }
Esempio n. 3
0
 public IEnumerable <PostSummary> GetPostSummaries()
 {
     return(repository.GetPostSummaries());
 }