public async Task <Reservation> Insert(Reservation reservation) { using (CarReservationContext context = new CarReservationContext()) { if (!DateRangeCheck(reservation)) { throw new InvalidDateRangeException( $"Reservation < 24h -> {(reservation.From - reservation.To).TotalHours}h"); } if (!await AvailabilityCheck(reservation)) { throw new CarUnavailableException($"car: {reservation.CarId} unavailable"); } context.Entry(reservation).State = EntityState.Added; await context.SaveChangesAsync(); reservation.Car = await context.Cars.FindAsync(reservation.CarId); await context.Entry(reservation).Reference(r => r.Customer).LoadAsync(); return(reservation); } }
public async Task Delete(Customer customer) { using (CarReservationContext context = new CarReservationContext()) { context.Entry(customer).State = EntityState.Deleted; await context.SaveChangesAsync(); } }
public async Task <Customer> Insert(Customer customer) { using (CarReservationContext context = new CarReservationContext()) { context.Entry(customer).State = EntityState.Added; await context.SaveChangesAsync(); return(customer); } }
public async Task Update(Customer customer) { using (CarReservationContext context = new CarReservationContext()) { try { context.Entry(customer).State = EntityState.Modified; await context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); throw CreateOptimisticConcurrencyException(context, customer); } } }
public async Task Update(Reservation reservation) { using (CarReservationContext context = new CarReservationContext()) { if (!DateRangeCheck(reservation)) { throw new InvalidDateRangeException( $"Reservation < 24h -> {(reservation.From - reservation.To).TotalHours}h"); } if (!await AvailabilityCheck(reservation)) { throw new CarUnavailableException($"car: {reservation.CarId} unavailable"); } context.Entry(reservation).State = EntityState.Modified; await context.SaveChangesAsync(); } }