@@ -48,6 +48,44 @@ public async Task<IActionResult> CreateBookingAsync(CreateBookingDto request, Gu
48
48
return new CreatedResult ( string . Empty , bookingDto ) ;
49
49
}
50
50
51
+ public async Task < IActionResult > CreateAutomaticBookingByRestaurantIdAsync ( CreateBookingDto createBookingDto , Guid userId , Guid restaurantId )
52
+ {
53
+ // TODO: Assign 17:30 and not like 17:36:35Z ...
54
+ var availableTable = await _unitOfWork . TableRepository . GetAvailableTableAsync ( restaurantId , createBookingDto . AmountOfPeople , createBookingDto . Date ) ;
55
+
56
+ if ( availableTable == null )
57
+ {
58
+ return new BadRequestObjectResult ( $ "No available table for { createBookingDto . AmountOfPeople } people at restaurant { restaurantId } ") ;
59
+ }
60
+
61
+ var newBooking = new Booking
62
+ {
63
+ Date = createBookingDto . Date ,
64
+ DurationInMinutes = createBookingDto . DurationInMinutes ,
65
+ TableId = availableTable . Id ,
66
+ AppUserId = userId ,
67
+ AmountOfPeople = createBookingDto . AmountOfPeople ,
68
+ Id = Guid . NewGuid ( ) ,
69
+ RestaurantId = availableTable . RestaurantId
70
+ } ;
71
+
72
+ await _unitOfWork . BookingRepository . InsertAsync ( newBooking ) ;
73
+ await _unitOfWork . SaveChangesAsync ( ) ;
74
+
75
+ var bookingDto = new BookingDto
76
+ {
77
+ Id = newBooking . Id ,
78
+ Date = newBooking . Date ,
79
+ DurationInMinutes = newBooking . DurationInMinutes ,
80
+ AmountOfPeople = newBooking . AmountOfPeople ,
81
+ AppUserId = userId ,
82
+ RestaurantId = newBooking . RestaurantId
83
+ } ;
84
+
85
+ return new CreatedResult ( string . Empty , bookingDto ) ;
86
+ }
87
+
88
+
51
89
public async Task < IActionResult > DeleteBookingAsync ( Guid bookingId , Guid userId )
52
90
{
53
91
var booking = await _unitOfWork . BookingRepository . GetBookingByIdForSpecificUserAsync ( bookingId , userId ) ;
0 commit comments