예제 #1
0
        private static EventFilterModelIn GetUserRequirements()
        {
            // todo: use reflection
            var filterModel = new EventFilterModelIn();

            filterModel.CountryPartName = GetValue(nameof(filterModel.CountryPartName));

            filterModel.CityPartName = GetValue(nameof(filterModel.CityPartName));

            filterModel.DateDepart = GetValue(nameof(filterModel.DateDepart))
                                     .TryToType <DateTime>();

            filterModel.Duration = GetValue(nameof(filterModel.Duration))
                                   .TryToType <int>();

            filterModel.MinHotelRating = GetValue(nameof(filterModel.MinHotelRating))
                                         .TryToType <int>();

            filterModel.MinSeaDistance = GetValue(nameof(filterModel.MinSeaDistance))
                                         .TryToType <int>();

            filterModel.NumberOfPeople = GetValue(nameof(filterModel.NumberOfPeople))
                                         .TryToType <int>();

            filterModel.Meal = GetValue(nameof(filterModel.Meal));

            filterModel.RoomType = GetValue(nameof(filterModel.RoomType));


            return(filterModel);
        }
        public static Func <Meal, bool> BuildMealFilterFunc(EventFilterModelIn model)
        {
            var builder = PredicateBuilder.New <Meal>(true);

            if (model.Meal != null)
            {
                builder = builder.And(t => t.Type.IndexOf(model.Meal, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            var filterFunc = builder.Compile();

            return(filterFunc);
        }
        public static Func <Tour, bool> BuildTourFilterFunc(EventFilterModelIn model)
        {
            var builder = PredicateBuilder.New <Tour>(true);

            if (model.DateDepart != null)
            {
                builder = builder.And(t => t.DateDepart == model.DateDepart);
            }

            if (model.Duration != null)
            {
                builder = builder.And(t => t.Duration.Equals(model.Duration));
            }

            var filterFunc = builder.Compile();

            return(filterFunc);
        }
        public static Func <Room, bool> BuildRoomFilterFunc(EventFilterModelIn model)
        {
            var builder = PredicateBuilder.New <Room>(true);

            if (model.NumberOfPeople != null)
            {
                builder = builder.And(t => t.Seats.Equals(model.NumberOfPeople));
            }

            if (model.RoomType != null)
            {
                builder = builder.And(t => t.Type.IndexOf(model.RoomType, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            var filterFunc = builder.Compile();

            return(filterFunc);
        }
        public static Func <Hotel, bool> BuildHotelFilterFunc(EventFilterModelIn model)
        {
            var builder = PredicateBuilder.New <Hotel>(true);

            if (!model.CityPartName.IsNullOrEmpty())
            {
                builder = builder.And(e => e.City.Name.IndexOf(model.CityPartName, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            if (!model.CountryPartName.IsNullOrEmpty())
            {
                builder = builder.And(e => e.City.Country.Name.IndexOf(model.CountryPartName, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            if (model.MinHotelRating.HasValue)
            {
                builder = builder.And(e => e.Rating >= model.MinHotelRating);
            }

            if (model.MinSeaDistance.HasValue)
            {
                builder = builder.And(e => e.SeaDistance <= model.MinSeaDistance);
            }

            var tourFilterFunc = BuildTourFilterFunc(model);

            builder = builder.And(e => e.Tours.Any(tourFilterFunc));

            var mealFilterFunc = BuildMealFilterFunc(model);

            builder = builder.And(e => e.Meals.Any(mealFilterFunc));

            var roomFilterFunc = BuildRoomFilterFunc(model);

            builder = builder.And(e => e.Rooms.Any(roomFilterFunc));

            var filterFunc = builder.Compile();

            return(filterFunc);
        }