Ejemplo n.º 1
0
        public async Task <PagedResultDto <PostDto> > GetAllPostPagingAsync(PostPagingRequest input)
        {
            var user = await GetCurrentUserAsync();

            var query = WorkScope.GetAll <Post>()
                        .WhereIf(input.LevelId.HasValue, x => x.LevelId == input.LevelId)
                        .WhereIf(!input.SearchText.IsNullOrWhiteSpace(), x => x.Title.Contains(input.SearchText))
                        .WhereIf(user.UserType == UserType.Hr, x => x.CreatorUserId == user.Id)
                        .WhereIf(input.JobType.HasValue, x => x.JobType == input.JobType)
                        .Include(x => x.Company)
                        .WhereIf(!input.CompanyName.IsNullOrWhiteSpace(), x => x.Company.FullNameCompany.Contains(input.CompanyName))
                        .Include(x => x.CompanyPostHashtags)
                        .WhereIf(input.HashtagId.HasValue, x => x.CompanyPostHashtags.Any(p => p.HashtagId == input.HashtagId))
                        .WhereIf(input.StartDate.HasValue, x => x.CreationTime >= input.StartDate)
                        .WhereIf(input.EndDate.HasValue, x => x.EndDate < input.EndDate)
                        .OrderByDescending(x => x.CreationTime);

            int totalCount = await query.CountAsync();

            var list = await query.PageBy((input.CurrentPage - 1) *input.PageSize, input.PageSize)
                       .Include(x => x.Level)
                       .Select(x => new PostDto
            {
                Id            = x.Id,
                Title         = x.Title,
                CreationTime  = x.CreationTime,
                NumberOfViews = x.NumberOfViews,
                CompanyName   = x.Company.Name,
                JobType       = x.JobType,
                EndDate       = x.EndDate,
                LevelId       = x.LevelId,
                LevelName     = x.Level.Name,
                Hashtags      = x.CompanyPostHashtags.Select(p => new HashtagCompanyPostModel
                {
                    HashtagName = p.Hashtag.Name,
                    HashtagId   = p.HashtagId
                }).ToList()
            }).ToListAsync();

            return(new PagedResultDto <PostDto>(totalCount, list));
        }
        public async Task <PagedResultDto <CompanyPostModel> > GetPostPaging(PostPagingRequest input)
        {
            var      queryHashtags   = WorkScope.GetAll <Hashtag>().WhereIf(input.PostType == PostType.Hashtag, x => x.HashtagUrl == input.SearchText);
            var      queryBranchJobs = WorkScope.GetAll <BranchJob>().WhereIf(input.PostType == PostType.BranchJob, x => x.BranchJobUrl == input.SearchText);
            DateTime localTime       = GetLocalTime();

            var query = WorkScope.GetAll <Post>().Include(x => x.Company)
                        .OrderByDescending(x => x.CreationTime)
                        .WhereIf(!input.SearchText.IsNullOrWhiteSpace() && input.PostType == PostType.All, x => x.Title == input.SearchText || x.Content == input.SearchText)
                        .WhereIf(!input.Location.IsNullOrWhiteSpace(), x => x.Company.Location.Contains(input.Location))
                        .Select(x => new
            {
                FullCompanyName = x.Company.FullNameCompany,
                CompanyName     = x.Company.Name,
                x.Company.Location,
                CompanyId = x.Company.Id,
                MaxSalary = x.MaxMoney,
                MinSalary = x.MinMoney,
                x.MoneyType,
                PostId = x.Id,
                x.PostUrl,
                x.Title,
                x.Company.Treatment,
                Thumbnail = x.Company.Assets.Where(p => p.FileType == FileType.Thumbnail)
                            .Select(p => new ObjectFile
                {
                    Id       = p.Id,
                    FileType = p.FileType,
                    Path     = p.Path
                }).FirstOrDefault(),
                TimeCreateNewJob = (int)(localTime - x.CreationTime).TotalHours,
                PostHashtags     = queryHashtags.Where(p => x.CompanyPostHashtags.Any(k => k.HashtagId == p.Id))
                                   .Select(p => new HashtagHomeModel
                {
                    HashtagId  = p.Id,
                    Name       = p.Name,
                    HashtagUrl = p.HashtagUrl
                }),
                CompanyJobs = queryBranchJobs.Where(p => x.Company.BranchJobCompanies.Any(k => k.BranchJobId == p.Id))
                              .Select(p => new BranchJobCompanyHome
                {
                    BranchJobId  = p.Id,
                    Name         = p.Name,
                    BranchJobUrl = p.BranchJobUrl
                })
            })
                        .WhereIf(input.PostType == PostType.BranchJob, x => x.CompanyJobs.Any())
                        .WhereIf(input.PostType == PostType.Hashtag, x => x.PostHashtags.Any())
                        .Select(x => new CompanyPostModel
            {
                FullCompanyName  = x.FullCompanyName,
                CompanyName      = x.CompanyName,
                Location         = x.Location,
                CompanyId        = x.CompanyId,
                MaxSalary        = x.MaxSalary,
                MinSalary        = x.MinSalary,
                MoneyType        = x.MoneyType,
                PostId           = x.PostId,
                PostUrl          = x.PostUrl,
                Title            = x.Title,
                Treatment        = x.Treatment,
                Thumbnail        = x.Thumbnail,
                TimeCreateNewJob = x.TimeCreateNewJob,
                PostHashtags     = x.PostHashtags.ToList(),
                CompanyJobs      = x.CompanyJobs.ToList()
            });


            int totalCount = await query.CountAsync();

            var list = await query.PageBy((input.CurrentPage - 1) *input.PageSize, input.PageSize)
                       .ToListAsync();

            return(new PagedResultDto <CompanyPostModel>(totalCount, list));
        }