Exemplo n.º 1
0
        public static IEnumerable <VacancyConditionalFilter> GetFilters(VacancyFilterModel model)
        {
            Expression <Func <Vacancy, bool> > title        = v => v.Title.ToLower().Contains(model.VacancyTitle.ToLower());
            Expression <Func <Vacancy, bool> > minRating    = v => v.User.Profile.Rating >= model.MinRating;
            Expression <Func <Vacancy, bool> > minExp       = v => v.User.Profile.Experience >= model.MinExpirience;
            Expression <Func <Vacancy, bool> > musiceGenres = v =>
                                                              v.VacancyFilter.JsonMusicGenres.FromJson <ICollection <MusicGenre> >()
                                                              .Any(m => model.MusicGenres.Any(m2 => m.Id == m2.Id));
            Expression <Func <Vacancy, bool> > musicianRoles = v => v.VacancyFilter.JsonMusicianRoles.FromJson <ICollection <MusicianRole> >()
                                                               .Any(m => model.MusicianRoles.Any(m2 => m.Id == m2.Id));
            Expression <Func <Vacancy, bool> > workTypes = v => v.VacancyFilter.JsonWorkTypes.FromJson <ICollection <WorkType> >()
                                                           .Any(m => model.WorkTypes.Any(m2 => m.Id == m2.Id));
            Expression <Func <Vacancy, bool> > cities = v => v.VacancyFilter.JsonCities.FromJson <ICollection <City> >()
                                                        .Any(m => model.Cities.Any(m2 => m.Id == m2.Id));


            var filters = new[]
            {
                model.ApplyTitle() ? new VacancyConditionalFilter(title) : null,
                model.ApplyMinRating() ? new VacancyConditionalFilter(minRating): null,
                model.ApplyMinExpirience() ? new VacancyConditionalFilter(minExp): null,
                model.ApplyCities() ? new VacancyConditionalFilter(cities): null,
                model.ApplyMusicGenres() ? new VacancyConditionalFilter(musiceGenres): null,
                model.ApplyMusicianRoles() ? new VacancyConditionalFilter(musicianRoles): null,
                model.ApplyWorkTypes() ? new VacancyConditionalFilter(workTypes): null
            };

            return(filters.Where(f => f != null));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SearchVacancies([FromBody] VacancyFilterModel model)
        {
            if (_webSession.UserType == UserType.Group)
            {
                model.UserType = UserType.Musician;
            }
            else if (_webSession.UserType == UserType.Musician)
            {
                model.UserType = UserType.Group;
            }

            var filters   = VacancyConditionalFilter.GetFilters(model);
            var vacancies = await _crudService.Where <Vacancy>(v => !v.IsClosed && v.User.Type == model.UserType);

            var foundVacancies = vacancies.ToList().Where(v => filters.All(f => f.PassFilter(v))).ToList();

            return(Ok(Mapper.Map <List <VacancyModel> >(foundVacancies)));
        }