Ejemplo n.º 1
0
        public ActionResult ToBook(BookingViewModel bookingVM)
        {
            bookingVM.UserId = User.Identity.GetUserId();
            if (bookingVM.CheckIn >= bookingVM.CheckOut)
            {
                ModelState.AddModelError("", "Введите корректный интервал дат!");
                return(View(bookingVM));
            }

            IEnumerable <BookingDTO> bookingDTO = booking.GetBookings();
            var bookings = from b in bookingDTO
                           where b.RoomId == bookingVM.RoomId
                           select b;

            foreach (var b in bookings)
            {
                if (bookingVM.CheckOut <= b.CheckIn || bookingVM.CheckIn >= b.CheckOut)
                {
                }
                else
                {
                    ModelState.AddModelError("", "Данная комната занята на эти даты!");
                    return(View(bookingVM));
                }
            }

            if (ModelState.IsValid)
            {
                Mapper.Reset();
                Mapper.Initialize(cfg => cfg.CreateMap <BookingViewModel, BookingDTO>());
                var bookingDto = Mapper.Map <BookingViewModel, BookingDTO>(bookingVM);
                booking.Book(bookingDto);
                return(View("BookedSuccessfully"));
            }
            return(View(bookingVM));
        }
Ejemplo n.º 2
0
 public JsonResult Confirm(BookingRequest request)
 {
     return(Json(bookie.Book(request)));
 }