public IActionResult GetAvailability(BookingInput bookingInput)
        {
            var maxPeople      = bookingInput.TotalAdults + bookingInput.TotalKids;
            var sql            = string.Format(@"SELECT A.id, B.Name as name, A.CategoryefId, A.HotelRefId, A.Photo,  B.MaxPeople as maxPeople, B.Price as price
FROM Rooms as A
INNER JOIN categories as B
ON B.id = A.CategoryefId
WHERE B.MaxPeople >= {0} 
AND (A.Id NOT IN (SELECT RoomRefBookingId
    FROM Bookings
    WHERE 
        (Bookings.StartDate <= '{1}' AND Bookings.EndDate >= '{2}') OR
        (Bookings.StartDate <= '{1}' AND Bookings.EndDate >= '{1}' AND Bookings.StartDate < '{2}') OR
        (Bookings.StartDate > '{1}' AND Bookings.StartDate <= '{2}' AND Bookings.StartDate < '{2}')
    AND A.id is NOT NULL))", maxPeople, bookingInput.ArrivalDate, bookingInput.DepartureDate);
            var availableRooms = _context.Rooms
                                 .Include(e => e.Category)
                                 .Include(e => e.Hotel)
                                 .FromSql(sql)
                                 .ToList();


            Console.WriteLine(sql);
            return(Ok(availableRooms));
        }
예제 #2
0
        public ActionResult <BookingOut> Book([FromBody] BookingInput input)
        {
            //  BookingInput booData = input;

            var apartT = _dataService.GetAllAppartments().Where(x => x.Id.ToString() == input.ApartmentId).First();

            BookingOut rzlt = new BookingOut();

            rzlt.ReservationNumber = Guid.NewGuid().ToString();

            BookRecords newBook = new BookRecords();

            newBook.FName             = input.Fname;
            newBook.lName             = input.Lname;
            newBook.Email             = input.Email;
            newBook.ReservationNumber = rzlt.ReservationNumber;
            newBook.StartDate         = input.StartDate;
            newBook.AType             = apartT;

            var bookRecords = _baseService.SaveBook(newBook);


            return(rzlt);
        }