示例#1
0
        public async Task <ActionResult> Create(int?id, BookingViewModel bookingViewModel)
        {
            if (id == null || bookingViewModel == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (!await _portalService.CreateBookingAsync(id, bookingViewModel))
            {
                ModelState.AddModelError("LastDay", "The room is already reserved at that day!");
            }

            if (!ModelState.IsValid)
            {
                ViewData["Capacity"]  = new SelectList(_portalService.CreateCapacityList(id));
                bookingViewModel.Room = _portalService.GetRoom(id);
                return(View("Create", bookingViewModel));
            }

            //TODO: return to the result view of the booking
            return(RedirectToAction("Index", "Home"));
        }