private OrderCar(RentalCarId rentalCarId, double pricePerDay, DateTime rentalStartDate, DateTime rentalEndDate) { Id = new OrderCarId(Guid.NewGuid()); RentalCarId = rentalCarId; PricePerDay = pricePerDay; RentalStartDate = rentalStartDate; RentalEndDate = rentalEndDate; }
public static OrderCar Create(RentalCarId rentalCarId, double pricePerDay, DateTime rentalStartDate, DateTime rentalEndDate) { if ((rentalEndDate - rentalStartDate).TotalDays < 1) { throw new OrderCarRentalTooShortException($"Cannot create car rental shorter than 1 day"); } return(new OrderCar(rentalCarId, pricePerDay, rentalStartDate, rentalEndDate)); }
public void AddAgencyRentalCar(AgencyId agencyId, RentalCarId rentalCarId) { var agency = agencies.FirstOrDefault(x => x.Id == agencyId); if (agency == null) { throw new AgencyNotFoundException($"Unable to add rental car. AgencyId: {agencyId} does not exists" + $"in a company with Id: {Id}"); } agency.AddRentalCar(rentalCarId); }
public void AddRentalCar(RentalCarId rentalCarId) { if (RentalCars.Any(x => x.Id == rentalCarId.Id)) { throw new RentalCarAlreadyAddedException($"Cannot add rentalCarId: {rentalCarId} because It exists in agency"); } if (RentalCars.Count > 30) { throw new RentalCarsInAgencyExceededException($"Agency cannot contains more than 30 cars"); } RentalCars.Add(rentalCarId); }