示例#1
0
        public ActionResult Index(RoomSearchVM roomSearchVM)
        {
            var isValid = true;

            if (roomSearchVM.AccomodationDate < DateTime.Today)
            {
                ModelState.AddModelError("AccomodationDate", "Accomodation date cannot be set before today");
                isValid = false;
            }

            if (roomSearchVM.AccomodationDate > roomSearchVM.CheckOutDate)
            {
                ModelState.AddModelError("CheckOutDate", "Check out date cannot be set before accomodation");
                isValid = false;
            }

            if (roomSearchVM.AccomodationDate == roomSearchVM.CheckOutDate)
            {
                ModelState.AddModelError("CheckOutDate", "Dates cannot be the same");
                isValid = false;
            }

            if (isValid)
            {
                this.reservationService.UpdateReservations();
                var foundRooms   = this.roomService.GetAvailableRooms(roomSearchVM.AccomodationDate, roomSearchVM.CheckOutDate, roomSearchVM.SelectedAmenityIds, roomSearchVM.NumberOfGuests, roomSearchVM.RoomSize);
                var foundRoomsVM = new List <RoomVM>();
                foreach (var foundRoom in foundRooms)
                {
                    var amenities       = this.roomService.GetAmenitiesOfRoom(foundRoom.RoomId);
                    var amenitiesString = new StringBuilder();
                    foreach (var amenity in amenities)
                    {
                        amenitiesString.Append(amenity.AmenityName + ", ");
                    }

                    foundRoomsVM.Add(new RoomVM
                    {
                        Amenities         = amenitiesString.ToString(),
                        Cost              = foundRoom.Cost,
                        MaxNumberOfGuests = foundRoom.MaxNumberOfGuests,
                        RoomNumber        = foundRoom.RoomId,
                        RoomSize          = foundRoom.RoomSize
                    });
                }
                roomSearchVM.FoundRooms = foundRoomsVM;
            }

            roomSearchVM.AmenitiesToSearch = roomService.GetAllAmenities().Select(a => new AmenitySearchVM
            {
                AmenityId   = a.AmenityId,
                AmenityName = a.AmenityName
            }).ToList();


            return(View(roomSearchVM));
        }
示例#2
0
        public ActionResult Index()
        {
            var roomSearchVM = new RoomSearchVM
            {
                AmenitiesToSearch = roomService.GetAllAmenities().Select(a => new AmenitySearchVM
                {
                    AmenityId   = a.AmenityId,
                    AmenityName = a.AmenityName
                }).ToList(),
                AccomodationDate = DateTime.Today,
                CheckOutDate     = DateTime.Today.AddDays(1)
            };

            return(View(roomSearchVM));
        }