public async Task <IActionResult> ReserveTable(TableServiceModel tableModel) { if (!ModelState.IsValid) { return(this.View(tableModel)); } bool success = await this.userService.ReserveTableAsync(tableModel.Number, tableModel.Date); if (!success) { TempData.AddErrorMessage("This date is taken."); return(this.View()); } TempData.AddSuccessMessage("Reservation is complete"); return(this.View()); }
private static void InitializeReservation(CreateReservationBindingModel viewModel, ReserveTableUserServiceModel user, RestaurantServiceModel restaurant, DateTime dateTime, ReservationServiceModel reservationServiceModel, TableServiceModel table) { reservationServiceModel.ForDate = dateTime; reservationServiceModel.SeatsCount = viewModel.SeatsCount; reservationServiceModel.UserId = user.Id; reservationServiceModel.TableId = table.Id; reservationServiceModel.RestaurantId = restaurant.Id; }
private async Task <ReservationServiceModel> FindTable(CreateReservationBindingModel viewModel, ReserveTableUserServiceModel user, RestaurantServiceModel restaurant, DateTime dateTime, ReservationServiceModel reservationServiceModel, TableServiceModel table) { if (table.Reservations.Any(t => (dateTime > t.ForDate && dateTime < t.EndOfReservation) && t.IsCancelled == false)) { return(null); } else { InitializeReservation(viewModel, user, restaurant, dateTime, reservationServiceModel, table); var reservation = AutoMapper.Mapper.Map <Reservation>(reservationServiceModel); await dbContext.Reservations.AddAsync(reservation); await dbContext.SaveChangesAsync(); return(reservationServiceModel); } }