public void AddRisk(string nameOfInsuredObject, Risk risk, DateTime validFrom, DateTime effectiveDate) { if (validFrom < effectiveDate) { throw new RiskValidityPeriodException(); } var policyId = IdGenerator.ConstructPolicyId(nameOfInsuredObject, effectiveDate); var policyModel = _policyRepository.Get(policyId); if (validFrom > policyModel.ValidTill) { throw new RiskValidityPeriodException(); } if (policyModel.InsuredRisks.Contains(risk)) { throw new DuplicateRiskException(risk.Name); } var riskId = IdGenerator.ConstructRiskId(risk.Name, policyModel.NameOfInsuredObject, effectiveDate); var riskModel = new RiskModel { Name = risk.Name, ValidFrom = validFrom, PolicyEffectiveDate = effectiveDate, PolicyId = policyId, Id = riskId, ValidTill = policyModel.ValidTill, YearlyPrice = risk.YearlyPrice }; _riskRepository.Add(riskModel); }
public IPolicy SellPolicy(IPolicy policy) { var policyId = IdGenerator.ConstructPolicyId(policy.NameOfInsuredObject, policy.ValidFrom); if (_policyRepository.Get(policyId) != null) { throw new DuplicatePolicyException(policy.NameOfInsuredObject, policy.ValidFrom); } var policyModel = new PolicyModel { Id = policyId, NameOfInsuredObject = policy.NameOfInsuredObject, ValidFrom = policy.ValidFrom, ValidTill = policy.ValidTill, InsuredRisks = policy.InsuredRisks, Premium = policy.Premium }; foreach (var risk in policy.InsuredRisks) { var riskId = IdGenerator.ConstructRiskId(risk.Name, policy.NameOfInsuredObject, policy.ValidFrom); var riskModel = new RiskModel { Name = risk.Name, ValidFrom = policy.ValidFrom, ValidTill = policy.ValidTill, PolicyEffectiveDate = policy.ValidFrom, PolicyId = policyId, Id = riskId, YearlyPrice = risk.YearlyPrice }; _riskRepository.Add(riskModel); } _policyRepository.Add(policyModel); return(policy); }
public Risk Add(Risk risk) { return(_risk.Add(risk)); }