public async Task <ActionResult <ReservationTimeSlot> > Reservation([FromBody] ReservationTimeSlot reservation) { string accountID = this.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (accountID == null) { return(Unauthorized()); } try { ParkingSpot parkingSpot = await parkingSpotManager.GetFreeParkingSpot(reservation.startReservation, reservation.endReservation); if (parkingSpot == null) { return(NotFound("No parking spots available")); } reservation.parkingSpotID = parkingSpot.parkingSpotID; reservation.accountID = accountID; ReservationTimeSlot newReservation = await reservationTimeSlotManager.CreateReservationTimeSlot(reservation); return(Ok(newReservation)); } catch (Exception) { return(BadRequest()); } }
public async Task <ActionResult <ReservationTimeSlot> > PostReservationTimeSlot([FromBody] ReservationTimeSlot reservationTimeSlot) { try { ReservationTimeSlot reservation = await reservationTimeSlotManager.CreateReservationTimeSlot(reservationTimeSlot); if (reservation == null) { return(BadRequest()); } return(Ok(reservation)); } catch (Exception) { return(BadRequest()); } }