示例#1
0
 public HttpResponseMessage Get([FromUri] int page, int pageSize, string sortColumn, bool reverceSort, string filter, string pool, string status, string addedBy)
 {
     try
     {
         var filterParams = new VacancyFilterParams
         {
             Page = page,
             PageSize = pageSize,
             SortColumn = sortColumn,
             ReverceSort = reverceSort,
             Filter = filter,
             Pool = pool,
             Status = status,
             AddedBy = addedBy
         };
         var vacancies = _vacancyService.Get(filterParams);
         vacancies.Rows.ForEach(x => x.PoolColors = _vacancyService.GetColors(x.Id));
         return Request.CreateResponse(HttpStatusCode.OK, vacancies);
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
     }
 }
示例#2
0
        public PageDto<VacancyRowDto> Get(VacancyFilterParams filterParams)
        {
            IQueryable<Vacancy> query = _vacancyRepository.QueryIncluding(v => v.Pool, v => v.UserProfile);

            if (filterParams.Pools.Any())
            {
                var selectedPools = filterParams.Pools.Select(Int32.Parse).ToList();
            //                query = query.Where(vac => selectedPools.Contains(vac.PoolId));
                query = query.Where(vac => selectedPools.Any(x => vac.Pool.Any(p => p.Id == x)));//??
            }

            if (filterParams.Statuses.Any())
            {
                var selectedStatuses = filterParams.Statuses.Select(Int32.Parse).ToList();
                query = query.Where(vac => selectedStatuses.Contains(vac.Status));
            }
            if (filterParams.Statuses.Any())
            {
                var selectedStatuses = filterParams.Statuses.Select(Int32.Parse).ToList();
                query = query.Where(vac => selectedStatuses.Contains(vac.Status));
            }

            if (filterParams.AddedByArray.Any())
            {
                var selectedCreators = filterParams.AddedByArray.Select(Int32.Parse).ToList();
                query = query.Where(vac => selectedCreators.Any(x=> vac.UserProfileId == x));
            }

            if (!string.IsNullOrWhiteSpace(filterParams.Filter))
            {
                var nameFilter = filterParams.Filter.ToLowerInvariant();
                query = query.Where(vac => vac.Name.Contains(nameFilter));
            }
            IOrderedQueryable<Vacancy> orderedQuery = null;
            if (filterParams.SortColumn == "startDate")
            {
                orderedQuery = filterParams.ReverceSort ? query.OrderByDescending(v => v.StartDate) : query.OrderBy(v => v.StartDate);
            }
            else if (filterParams.SortColumn == "name")
            {
                orderedQuery = filterParams.ReverceSort ? query.OrderByDescending(v => v.Name) : query.OrderBy(v => v.Name);
            }
            else
            {
                orderedQuery = query.OrderByDescending(v => v.StartDate);
            }

            var countRecords = query.Count();

            var vacanciesFiltered = orderedQuery.Skip((filterParams.Page - 1) * filterParams.PageSize).Take(filterParams.PageSize).ToList();

            var list = vacanciesFiltered.Select(item => item.ToRowDto()).ToList();
            return new PageDto<VacancyRowDto>
            {
                TotalCount = countRecords,
                Rows = list
            };
        }