예제 #1
0
        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());
        }
예제 #2
0
 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;
 }
예제 #3
0
        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);
            }
        }