コード例 #1
0
 public IActionResult Index(RoomSearchModel roomSearchModel)
 {
     if (!ModelState.IsValid)
     {
         ViewData["Cities"]    = formBuilder.GetCities();
         ViewData["RoomTypes"] = formBuilder.GetRoomTypes();
         return(View(roomSearchModel));
     }
     return(RedirectToAction("SearchResults", "Search", roomSearchModel));
 }
コード例 #2
0
ファイル: SearchController.cs プロジェクト: Gennerys/belob
        public IActionResult SearchResults(RoomSearchModel searchModel)
        {
            ViewData["Cities"]      = formBuilder.GetCities();
            ViewData["RoomTypes"]   = formBuilder.GetRoomTypes();
            ViewData["SearchModel"] = searchModel;
            IEnumerable <Room> results;

            if (ModelState.IsValid)
            {
                results = roomSearchBuilder.Build(searchModel);
            }
            else
            {
                results = new List <Room>();
            }
            return(View(results));
        }
コード例 #3
0
        /// <summary>
        /// Осуществляет поиск по полям, заданным в модели
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <List <Room> > SearchAsync(RoomSearchModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException($"Ссылка на модель указывает на null.");
            }

            if (model.MinPeoplecount >= model.MaxPeopleCount)
            {
                throw new ArgumentException(
                          $"Минимум не может быть больше или равен максимуму({model.MinPeoplecount}>!{model.MaxPeopleCount})");
            }

            //Нужно для проверки на тип комнаты
            var list = new List <RoomOptions>();

            if (model.IsStandart)
            {
                list.Add(RoomOptions.Standard);
            }
            if (model.IsHalfLux)
            {
                list.Add(RoomOptions.HalfLux);
            }
            if (model.IsLux)
            {
                list.Add(RoomOptions.Lux);
            }

            var min = model.MinPeoplecount;
            var max = model.MaxPeopleCount;

            var result = Rooms.Where(x => x.IsFree &&
                                     x.MaxCount >= min &&
                                     x.MaxCount <= max);

            //Елси хотя бы 1 критерий выбран, то так же ищем по типу номера
            if (model.IsStandart || model.IsHalfLux || model.IsLux)
            {
                result = result.Where(x => list.Contains(x.RoomOptionId));
            }
            return(result.ToList());
        }
コード例 #4
0
ファイル: RoomSearchBuilder.cs プロジェクト: Gennerys/belob
        public IEnumerable <Room> Build(RoomSearchModel roomSearchModel)
        {
            IEnumerable <Room> results;

            if (roomSearchModel != null)
            {
                results = wdaContext.Room.Include(room => room.RoomType).AsQueryable();
                results = results.Where(room => room.City.Equals(roomSearchModel.City));
                results = results.Where(room => room.RoomTypeId.Equals(roomSearchModel.RoomType));

                var bookings = wdaContext.Bookings.Where(booking => booking.CheckInDate.CompareTo(roomSearchModel.CheckOutDate) <= 0 &&
                                                         roomSearchModel.CheckInDate.CompareTo(booking.CheckOutDate) <= 0);

                results = results.Where(r => !bookings.Any(b => b.RoomId.Equals(r.RoomId)));

                if (roomSearchModel.GuestsCount != null)
                {
                    results = results.Where(room => room.CountOfGuests >= roomSearchModel.GuestsCount);
                }

                if (roomSearchModel.PriceMin != null && roomSearchModel.PriceMin != 0)
                {
                    results = results.Where(room => room.Price >= roomSearchModel.PriceMin);
                }

                if (roomSearchModel.PriceMax != null && roomSearchModel.PriceMax != 5000)
                {
                    results = results.Where(room => room.Price <= roomSearchModel.PriceMax);
                }
            }
            else
            {
                results = wdaContext.Room;
            }

            results = results.OrderBy(room => room.Price);
            return(results);
        }
コード例 #5
0
        public async Task <object> GetVisitors([FromBody] RoomSearchModel model)
        {
            var resultList = await _roomService.SearchAsync(model);

            return(resultList.Select(x => x?.RoomView()));
        }