Esempio n. 1
0
        public IActionResult Holidays(BookingConflictViewModel viewModel, bool confirmDelete = false)
        {
            if (viewModel.ConflictedBooking != null && viewModel.ConflictedBooking.Any())
            {
                if (confirmDelete)
                {
                    foreach (var deletedBooking in viewModel.ConflictedBooking)
                    {
                        bookingService.Delete(deletedBooking.Id);
                    }
                }
                else
                {
                    foreach (var item in ModelState)
                    {
                        if (item.Key.Contains("ConflictedBooking"))
                        {
                            ModelState.ClearValidationState(item.Key);
                            ModelState.MarkFieldValid(item.Key);
                        }
                    }
                }
            }


            var holidayConflictions = holidayService.FindConflicts(viewModel.InputtedHoliday);

            if (holidayConflictions.Any())
            {
                viewModel.ConflictedBooking = holidayConflictions;
                return(View(viewModel));
            }


            var status = holidayService.AddHolidayBooking(viewModel.InputtedHoliday);

            if (status == HolidayBookingStatus.OK)
            {
                return(RedirectToAction("List"));
            }

            ModelState.AddModelError(string.Empty, HolidayErrorMessageLookup[status]);

            return(View(viewModel));
        }