public PagedResultDto <ArticleDto> GetLastArticles([FromQuery] ArticleSearchDto searchDto)
        {
            var select = _articleRepository
                         .Select
                         .Include(r => r.Classify)
                         .IncludeMany(r => r.Tags)
                         .WhereIf(searchDto.TagId.HasValue, r => r.Tags.Any(u => u.Id == searchDto.TagId))
                         .WhereIf(searchDto.ClassifyId.HasValue, r => r.ClassifyId == searchDto.ClassifyId)
                         .WhereIf(searchDto.Title.IsNotNullOrEmpty(), r => r.Title.Contains(searchDto.Title))
                         .OrderByDescending(r => r.CreateTime);

            var articles = select
                           .ToPagerList(searchDto, out long totalCount)
                           .Select(a =>
            {
                ArticleDto articleDto = _mapper.Map <ArticleDto>(a);
                articleDto.Tags       = a.Tags.Select(r => new TagDto()
                {
                    TagName = r.TagName,
                    Id      = r.Id,
                }).ToList();
                articleDto.ThumbnailDisplay = _currentUser.GetFileUrl(articleDto.Thumbnail);
                return(articleDto);
            })
                           .ToList();

            return(new PagedResultDto <ArticleDto>(articles, totalCount));
        }
        public async Task <List <ArticleDto> > SearchAsync(ArticleSearchDto searchDto)
        {
            var articles = await _bus.Send(new GetArticlesQuery());

            var articleDtos = new List <ArticleDto>(articles.Count);

            var duplicateIds = new List <int>();

            foreach (var article in articles)
            {
                var articleDto = new ArticleDto
                {
                    Id      = article.Id,
                    Content = article.Content,

                    DuplicateIds = await _articleSimilarityService.FindDuplicatesAsync(article)
                };

                if (searchDto.IsUniqueOnly && duplicateIds.Contains(articleDto.Id))
                {
                    continue;
                }

                articleDtos.Add(articleDto);
                duplicateIds.AddRange(articleDto.DuplicateIds);
            }

            return(articleDtos);
        }
        public void TestWhereOneToMany()
        {
            ArticleSearchDto searchDto = new ArticleSearchDto()
            {
                TagId = new Guid("5dc931fd-5e44-c190-008e-3fc4728735d6")
            };

            var data1 = _articleRepository
                        .Select
                        .IncludeMany(r => r.Tags)
                        .Where(r => r.Tags.AsSelect().Any(u => u.Id == searchDto.TagId)).ToList();

            var data2 = _articleRepository
                        .Select
                        .Where(r => r.Tags.AsSelect().Where(u => u.Id == searchDto.TagId).Count() > 0).ToList();

            var data3 = _articleRepository
                        .Select
                        .IncludeMany(r => r.Tags.Take(10)).ToList();

            var data4 = _articleRepository
                        .Select
                        .IncludeMany(r => r.Tags).ToList();

            //注意这里where填写的是u=>u.Id==r.Id
            var data5 = _articleRepository
                        .Select
                        .IncludeMany(r => r.Tags.Where(u => u.Id == r.Id)).ToList();

            //System.Exception:“表达式错误,它不是连续的 MemberAccess 类型:value(LinCms.Test.Controller.v1.ArticleControllerTest+<>c__DisplayClass9_0).searchDto”
            var data = _articleRepository
                       .Select
                       .IncludeMany(r => r.Tags.Where(u => u.Id == searchDto.TagId)).ToList();
        }
        public async Task <PagedResultDto <ArticleListDto> > GetArticleAsync([FromQuery] ArticleSearchDto searchDto)
        {
            return(await _articleService.GetArticleAsync(searchDto));

            //string redisKey = "article:query:" + searchDto.ToString();
            //return await RedisHelper.CacheShellAsync(
            //    redisKey, 3600, async () => await _articleService.GetArticleAsync(searchDto)
            //   );
        }
Beispiel #5
0
        public async Task <PagedResultDto <ArticleListDto> > GetArticleAsync([FromQuery] ArticleSearchDto searchDto)
        {
            //return await _articleService.GetArticleAsync (searchDto);
            string redisKey = "article:query:" + JsonConvert.SerializeObject(searchDto, Formatting.Indented, new JsonSerializerSettings
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            });

            return(await RedisHelper.CacheShellAsync(
                       redisKey, 60, async() => await _articleService.GetArticleAsync(searchDto)
                       ));
        }
        public PagedResultDto <ArticleListDto> GetAllArticles([FromQuery] ArticleSearchDto searchDto)
        {
            var articles = _articleRepository
                           .Select
                           .WhereCascade(r => r.IsDeleted == false)
                           .WhereIf(searchDto.Title.IsNotNullOrEmpty(), r => r.Title.Contains(searchDto.Title))
                           .OrderByDescending(r => r.CreateTime)
                           .ToPagerList(searchDto, out long totalCount)
                           .Select(a => _mapper.Map <ArticleListDto>(a))
                           .ToList();

            return(new PagedResultDto <ArticleListDto>(articles, totalCount));
        }
        public Task <PagedResultDto <ArticleListDto> > GetArticleAsync([FromQuery] ArticleSearchDto searchDto)
        {
            return(_articleService.GetArticleAsync(searchDto));

            //string redisKey = "article:query:" + EncryptUtil.Encrypt(JsonConvert.SerializeObject(searchDto, Formatting.Indented, new JsonSerializerSettings
            //{
            //    DefaultValueHandling = DefaultValueHandling.Ignore
            //}));

            //return RedisHelper.CacheShellAsync(
            //    redisKey, 60, () => _articleService.GetArticleAsync(searchDto)
            // );
        }
        public PagedResultDto <ArticleDto> QueryArticles([FromQuery] ArticleSearchDto searchDto)
        {
            DateTime monthDays  = DateTime.Now.AddDays(-30);
            DateTime weeklyDays = DateTime.Now.AddDays(-7);
            DateTime threeDays  = DateTime.Now.AddDays(-3);

            long?userId = _currentUser.Id;
            ISelect <Article> articleSelect = _articleRepository
                                              .Select
                                              .Include(r => r.Classify)
                                              .Include(r => r.UserInfo)
                                              .IncludeMany(r => r.Tags, r => r.Where(u => u.Status == true))
                                              .IncludeMany(r => r.UserLikes, r => r.Where(u => u.CreateUserId == userId))
                                              .Where(r => r.IsAudit == true)
                                              .WhereCascade(r => r.IsDeleted == false)
                                              .WhereIf(searchDto.UserId != null, r => r.CreateUserId == searchDto.UserId)
                                              .WhereIf(searchDto.TagId.HasValue, r => r.Tags.AsSelect().Any(u => u.Id == searchDto.TagId))
                                              .WhereIf(searchDto.ClassifyId.HasValue, r => r.ClassifyId == searchDto.ClassifyId)
                                              .WhereIf(searchDto.ChannelId.HasValue, r => r.ChannelId == searchDto.ChannelId)
                                              .WhereIf(searchDto.Title.IsNotNullOrEmpty(), r => r.Title.Contains(searchDto.Title))
                                              .WhereIf(searchDto.Sort == "THREE_DAYS_HOTTEST", r => r.CreateTime > threeDays)
                                              .WhereIf(searchDto.Sort == "WEEKLY_HOTTEST", r => r.CreateTime > weeklyDays)
                                              .WhereIf(searchDto.Sort == "MONTHLY_HOTTEST", r => r.CreateTime > monthDays)
                                              .OrderByDescending(
                searchDto.Sort == "THREE_DAYS_HOTTEST" || searchDto.Sort == "WEEKLY_HOTTEST" || searchDto.Sort == "MONTHLY_HOTTEST" ||
                searchDto.Sort == "HOTTEST",
                r => (r.ViewHits + r.LikesQuantity * 20 + r.CommentQuantity * 30))
                                              .OrderByDescending(r => r.CreateTime);

            List <ArticleDto> articleDtos = articleSelect
                                            .ToPagerList(searchDto, out long totalCount)
                                            .Select(a =>
            {
                ArticleDto articleDto = _mapper.Map <ArticleDto>(a);
                articleDto.Tags       = a.Tags.Select(r => new TagDto()
                {
                    TagName = r.TagName,
                    Id      = r.Id,
                }).ToList();

                articleDto.IsLiked = userId != null && a.UserLikes.Any();

                articleDto.ThumbnailDisplay = _currentUser.GetFileUrl(articleDto.Thumbnail);
                return(articleDto);
            })
                                            .ToList();

            return(new PagedResultDto <ArticleDto>(articleDtos, totalCount));
        }
        public PagedResultDto <ArticleListDto> Get([FromQuery] ArticleSearchDto searchDto)
        {
            List <ArticleListDto> articles = _articleRepository
                                             .Select
                                             .IncludeMany(r => r.Tags, r => r.Where(u => u.Status == true))
                                             .Where(r => r.CreateUserId == _currentUser.Id)
                                             .WhereIf(searchDto.Title.IsNotNullOrEmpty(), r => r.Title.Contains(searchDto.Title))
                                             .WhereIf(searchDto.ClassifyId.HasValue, r => r.ClassifyId == searchDto.ClassifyId)
                                             .OrderByDescending(r => r.IsStickie)
                                             .OrderByDescending(r => r.Id)
                                             .ToPagerList(searchDto, out long totalCount)
                                             .Select(a => _mapper.Map <ArticleListDto>(a))
                                             .ToList();

            return(new PagedResultDto <ArticleListDto>(articles, totalCount));
        }
Beispiel #10
0
        /// <summary>
        /// ブログ記事を取得する。
        /// </summary>
        /// <param name="param">検索条件。</param>
        /// <returns>ブログ記事。</returns>
        public async Task <IList <Article> > FindAll(ArticleSearchDto param)
        {
            // 検索条件がある場合はそれを使用して検索する
            IQueryable <Article> query = this.context.Articles.Include(a => a.Tags);

            if (param.BlogId > 0)
            {
                query = query.Where(a => a.BlogId == param.BlogId);
            }

            if (!string.IsNullOrWhiteSpace(param.Tag))
            {
                query = query.Where(a => a.Tags.Any(t => t.Name == param.Tag));
            }

            if (param.StartAt != null)
            {
                query = query.Where(a => a.CreatedAt >= param.StartAt);
            }

            if (param.EndAt != null)
            {
                query = query.Where(a => a.CreatedAt <= param.EndAt);
            }

            // 新しい順にソート
            query = query.OrderByDescending(a => a.CreatedAt).ThenByDescending(a => a.Id);

            // ページング条件がある場合は適用
            if (param.Skip > 0)
            {
                query = query.Skip(param.Skip);
            }

            if (param.Take > 0)
            {
                query = query.Take(param.Take);
            }

            return(await query.ToListAsync());
        }
        public PagedResultDto <ArticleDto> Get([FromQuery] ArticleSearchDto searchDto)
        {
            var select = _articleRepository
                         .Select
                         .IncludeMany(r => r.Tags)
                         .Where(r => r.CreateUserId == _currentUser.Id)
                         .WhereIf(searchDto.Title.IsNotNullOrEmpty(), r => r.Title.Contains(searchDto.Title))
                         .OrderByDescending(r => r.IsStickie)
                         .OrderByDescending(r => r.Id);

            var articles = select
                           .ToPagerList(searchDto, out long totalCount)
                           .Select(a =>
            {
                ArticleDto articleDto = _mapper.Map <ArticleDto>(a);
                return(articleDto);
            })
                           .ToList();

            return(new PagedResultDto <ArticleDto>(articles, totalCount));
        }
 public async Task <ActionResult <IEnumerable <ArticleDto> > > GetArticles([FromQuery] ArticleSearchDto query)
 {
     return((await this.articleService.FindArticles(query)).ToList());
 }
Beispiel #13
0
 public Task <List <ArticleDto> > Get([FromQuery] ArticleSearchDto searchDto)
 {
     return(_articleService.SearchAsync(searchDto));
 }
Beispiel #14
0
 /// <summary>
 /// ブログ記事一覧を取得する。
 /// </summary>
 /// <param name="param">検索条件。</param>
 /// <returns>ブログ記事一覧。</returns>
 public async Task <IEnumerable <ArticleDto> > FindArticles(ArticleSearchDto param)
 {
     return(this.mapper.Map <IEnumerable <ArticleDto> >(await this.articleRepository.FindAll(param)));
 }