CreateReservation([FromBody] ReservationPostDto reservation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var availability = await _context.Availabilities .Include(a => a.Reservation) .Include(a => a.Venue) .FirstOrDefaultAsync( a => a.Date == reservation.EventDate && a.VenueCode == reservation.VenueCode); if (availability == null || availability.Reservation != null) { return(BadRequest("Venue is not available on the requested date.")); } availability.Reservation = new Reservation { Reference = $"{availability.VenueCode}{availability.Date:yyyyMMdd}", EventDate = availability.Date, VenueCode = availability.VenueCode, WhenMade = DateTime.Now, StaffId = reservation.StaffId }; await _context.SaveChangesAsync(); return(CreatedAtAction("GetReservation", new { reference = availability.Reservation.Reference }, ReservationGetDto.FromModel(availability.Reservation))); }
public async Task <IActionResult> GetReservation([FromRoute] string reference) { var reservation = await _context.Reservations.FindAsync(reference); if (reservation == null) { return(NotFound()); } return(Ok(ReservationGetDto.FromModel(reservation))); }
public async Task <IActionResult> GetReservation([FromRoute] string reference) { var reservation = await _context.Reservations .Include(r => r.Availability) .ThenInclude(a => a.Venue) .FirstOrDefaultAsync(r => r.Reference == reference); if (reservation == null) { return(NotFound()); } return(Ok(ReservationGetDto.FromModel(reservation))); }
public async Task <IActionResult> DeleteReservation([FromRoute] string reference) { var reservation = await _context.Reservations.FindAsync(reference); if (reservation == null) { return(NotFound()); } _context.Reservations.Remove(reservation); await _context.SaveChangesAsync(); return(Ok(ReservationGetDto.FromModel(reservation))); }
public async Task <IActionResult> DeleteReservation([FromRoute] string reference) { var reservation = await _context.Reservations .Include(r => r.Availability) .ThenInclude(a => a.Venue) .FirstOrDefaultAsync(r => r.Reference == reference); if (reservation == null) { return(NotFound()); } var dto = ReservationGetDto.FromModel(reservation); _context.Reservations.Remove(reservation); await _context.SaveChangesAsync(); return(Ok(dto)); }