Esempio n. 1
0
        private SearchResponseDTO <Vacancy> SearchVacanciesWithQuery(SearchVacancyParameterDTO parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Page.HasValue && parameters.Page.Value < 0 ||
                parameters.PerPage.HasValue && parameters.PerPage.Value < 0)
            {
                throw new InvalidPaginationParametersException();
            }

            IQueryable <Vacancy> query = GetVacanciesSearchQuery(parameters);

            int totalCount = query.Count();

            if (parameters.Page.HasValue && parameters.Page != 0 && parameters.PerPage.HasValue)
            {
                query = query.Skip((parameters.Page.Value - 1) * parameters.PerPage.Value);
            }

            if (parameters.PerPage.HasValue)
            {
                query = query.Take(parameters.PerPage.Value);
            }

            List <Vacancy> vacancies = query.ToList();

            return(new SearchResponseDTO <Vacancy>
            {
                Items = vacancies,
                TotalCount = totalCount
            });
        }
Esempio n. 2
0
        private IQueryable <Vacancy> GetVacanciesSearchQuery(SearchVacancyParameterDTO parameters)
        {
            IQueryable <Vacancy> query = _queryBuilder.SetBaseVacanciesInfo()
                                         .SetPosition(_mapper.Map <Position?>(parameters.Position))
                                         .SetProfession(_mapper.Map <Profession?>(parameters.Profession))
                                         .SetPrimaryTechnology(_mapper.Map <Technology?>(parameters.PrimaryTechnology))
                                         .SetExperience(parameters.ExperienceFrom, parameters.ExperienceTo)
                                         .SetMyVacancies(parameters.MyVacancies, parameters.UserId)
                                         .Build();

            return(query);
        }
        public async Task <IActionResult> Filter([FromQuery] SearchVacancyParameterDTO parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            parameters.UserId = await GetCurrentUserId();

            SearchResponseDTO <VacancyDTO> result = _service.SearchVacancies(parameters);

            return(Ok(result));
        }
Esempio n. 4
0
        public SearchResponseDTO <VacancyDTO> SearchVacancies(SearchVacancyParameterDTO parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            SearchResponseDTO <Vacancy> result = SearchVacanciesWithQuery(parameters);

            return(new SearchResponseDTO <VacancyDTO>
            {
                Items = _mapper.Map <IEnumerable <VacancyDTO> >(result.Items),
                TotalCount = result.TotalCount
            });
        }