public ActionResult ToBookForManager(BookingViewModel bookingVM) { 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); application.BookForManager(bookingDto); return(View("BookedSuccessfully")); } return(View(bookingVM)); }