public async Task <Rental> RegisterRental(DateTime from, DateTime to, int carMilageKm, long customerId, long rentalCarId) { var carRentals = await this.unitOfWork.Rental.GetRentals(rentalCarId : rentalCarId); if (carRentals.Any(c => c.ReturnedAt == null && IsOverlapping(interval1: (c.From, c.To), interval2: (from, to)))) { throw new ArgumentException("Car is not available!"); } var rentalCar = await this.unitOfWork.RentalCar.Get(rentalCarId : rentalCarId); rentalCar.MilageKm = carMilageKm; this.unitOfWork.RentalCar.Update(rentalCar: rentalCar); var bookingNumber = Guid.NewGuid().ToString(); var newRental = new DAL.Models.Rental() { BookingNumber = bookingNumber, From = from, To = to, RentalCarId = rentalCarId, CustomerId = customerId, ReturnedAt = null, PaidPrice = null, }; await this.unitOfWork.Rental.Add(rental : newRental); await this.unitOfWork.CompleteAsync(); return(this.rentalConverter.Convert(rental: newRental)); }
public Rental Convert(DAL.Models.Rental rental) { return(new Rental( idRental: rental.IdRental, bookingNumber: rental.BookingNumber, from: rental.From, to: rental.To, customer: Convert(rental.Customer), rentalCar: Convert(rental.RentalCar), returnedAt: rental.ReturnedAt, paidPrice: rental.PaidPrice)); }