Beispiel #1
0
        public async Task <IReadOnlyList <ImageDto> > GetAllAsync()
        {
            var images = await cache.CacheAsync(
                CacheKeys.AllImages.Name,
                CacheKeys.AllImages.TimeToLive,
                () => imageRepository.FindAsync());

            return(mapper.Map <IReadOnlyList <ImageDto> >(images));
        }
Beispiel #2
0
        public async Task <IReadOnlyList <CommentDto> > GetAllCommentsAsync()
        {
            using var activity = traceActivityDecorator.StartActivity();
            var cacheKey = CacheKeys.AllComments;

            return(await cache.CacheAsync(cacheKey.Name, cacheKey.TimeToLive, async() =>
            {
                var dbModels = await commentRepository.FindAsync();
                return mapper.Map <List <CommentDto> >(dbModels).ToList();
            }));
        }
Beispiel #3
0
        public async Task <IReadOnlyList <TagDto> > GetAllTagsAsync(bool includeUnpublished)
        {
            var cacheKey = includeUnpublished ? CacheKeys.AllTags : CacheKeys.AllPublishedTags;

            return(await cache.CacheAsync(cacheKey.Name, cacheKey.TimeToLive, async() =>
            {
                var tags = await tagRepository.FindAsync();
                if (includeUnpublished)
                {
                    return mapper.Map <List <TagDto> >(tags);
                }

                var articles = await articleRepository.FindAsync();
                var published = mapper.Map <List <ArticleDto> >(articles).Where(x => x.IsPublished()).ToList();

                var publishedTags = tags.Where(x => published.Any(article => article.Id.ToString() == x.ArticleId)).ToList();
                return mapper.Map <List <TagDto> >(publishedTags);
            }));
        }
Beispiel #4
0
        public async Task <IReadOnlyList <ArticleDto> > GetAllArticlesAsync(bool includeUnpublished)
        {
            using var activity = traceActivityDecorator.StartActivity();
            var cacheKey = includeUnpublished ? CacheKeys.AllArticles : CacheKeys.AllPublishedArticles;

            return(await cache.CacheAsync(
                       cacheKey.Name,
                       cacheKey.TimeToLive,
                       () => FindAsync(includeUnpublished)));
        }