コード例 #1
0
        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);
            }
        }
コード例 #2
0
 public async Task Delete(Customer customer)
 {
     using (CarReservationContext context = new CarReservationContext())
     {
         context.Entry(customer).State = EntityState.Deleted;
         await context.SaveChangesAsync();
     }
 }
コード例 #3
0
        public async Task <Customer> Insert(Customer customer)
        {
            using (CarReservationContext context = new CarReservationContext())
            {
                context.Entry(customer).State = EntityState.Added;
                await context.SaveChangesAsync();

                return(customer);
            }
        }
コード例 #4
0
 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);
         }
     }
 }
コード例 #5
0
        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();
            }
        }