public async Task <ActionResult <Member> > AddMember(Member member) { var entityEntry = _context.Members.Add(member); await _context.SaveChangesAsync(); return(entityEntry.Entity); }
public async Task <ActionResult <Court> > AddCourt(Court court) { var entityEntry = _context.Courts.Add(court); await _context.SaveChangesAsync(); return(entityEntry.Entity); }
public async Task <ActionResult <Booking> > AddBooking(Booking booking) { var court = await _context.Courts.FindAsync(booking.CourtId); if (court.OpenTime.TimeOfDay > booking.StartTime.TimeOfDay || court.CloseTime.TimeOfDay < booking.EndTime.TimeOfDay) { return(BadRequest("The chosen time is not business hours")); } var overlappingBookings = await _context.Bookings.Where(b => b.CourtId == booking.CourtId) .Where(b => b.StartTime > booking.StartTime && b.StartTime <booking.EndTime || b.EndTime> booking.StartTime && b.EndTime < booking.EndTime).ToListAsync(); if (overlappingBookings.Any()) { return(BadRequest("The time has been booked")); } var entityEntry = _context.Bookings.Add(booking); await _context.SaveChangesAsync(); return(entityEntry.Entity); }