public void RemoveRisk(string nameOfInsuredObject, Risk risk, DateTime validTill, DateTime effectiveDate) { var policy = GetInternalPolicy(nameOfInsuredObject, effectiveDate); var policyAggregate = new PolicyAggregate(policy); policyAggregate.RemoveRisk(risk, validTill); policyRepository.Update(policy); }
public void AddRisk(string nameOfInsuredObject, Risk risk, DateTime validFrom, DateTime effectiveDate) { if (!AvailableRisks.Contains(risk)) { throw new AddedRiskUnavailableException("Added risk is not avaiable for selling"); } var policy = GetInternalPolicy(nameOfInsuredObject, effectiveDate); var policyAggregate = new PolicyAggregate(policy); policyAggregate.AddRisk(risk, validFrom); policyRepository.Update(policy); }
public IPolicy SellPolicy(string nameOfInsuredObject, DateTime validFrom, short validMonths, IList <Risk> selectedRisks) { var insurancePeriod = new NewInsurancePeriod(validFrom, validMonths); var effectivePolicies = GetEffectivePolicies(nameOfInsuredObject, insurancePeriod); if (effectivePolicies.Any()) { throw new ExistingEffectivePolicyException("Effective policy found that conflicts with requested validity period"); } if (selectedRisks.Except(AvailableRisks).Any()) { throw new InitialSelectedRiskUnavailableException("Some of the selected risks are not avaiable for selling"); } var policy = new Policy(); var policyAggregate = new PolicyAggregate(policy); policyAggregate.Create(nameOfInsuredObject, insurancePeriod, selectedRisks); policyRepository.Add(policy); return(policy); }