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 AddCompanyAgency(AgencyId agencyId, IDateTimeProvider dateTimeProvider) { if (agencies.Count == 10) { throw new AddCompanyAgencyRejectedException("Company cannot contains more than 10 Agencies"); } AgencyRole role; if (agencies.Count == 0) { role = AgencyRole.Headquarter; } else { role = AgencyRole.Standard; } agencies.Add(Agency.Create(agencyId, role, dateTimeProvider)); }
public void ChangeCompanyHeadquarter(AgencyId newHeadquarterId, IDateTimeProvider provider) { if (agencies.Count == 0) { throw new ChangeCompanyHeadquarterRejectedException("Company headquarter cannot be changed. Company does not contain any agency"); } var currentHQ = agencies.First(x => x.Role == AgencyRole.Headquarter); currentHQ.ChangeRoleToStandard(provider); var newHQ = agencies.FirstOrDefault(x => x.Id == newHeadquarterId); if (newHQ == null) { throw new ChangeCompanyHeadquarterRejectedException($"Company headquarter cannot be changed. " + $"Provided '{nameof(AgencyId)}': {newHeadquarterId} not exists in a company"); } newHQ.ChangeRoleToHeadquarter(provider); }