コード例 #1
0
        public void AddRisk(Risk risk, DateTime validFrom)
        {
            if (policy.InsuredRisks.Any(r => r.Name.ToLowerInvariant() == risk.Name.ToLowerInvariant()))
            {
                throw new ExistingRiskException("Risk with such name is already insured");
            }

            var insurancePeriod        = new NewInsurancePeriod(validFrom, policy.ValidTill);
            var newRiskInsurancePeriod = new RiskInsurancePeriod(insurancePeriod, risk);
            var addedPremiumForNewRisk = newRiskInsurancePeriod.CalculatePremium();

            policy.Premium += addedPremiumForNewRisk;
            policy.InsuredRisks.Add(risk);
        }
コード例 #2
0
        public void RemoveRisk(Risk risk, DateTime validTill)
        {
            if (!policy.InsuredRisks.Any(r => r.Name.ToLowerInvariant() == risk.Name.ToLowerInvariant()))
            {
                throw new InvalidRiskException("Risk with such name is not insured");
            }
            var calculateReturnedPremiumFrom = validTill.AddMonths(1);

            if (calculateReturnedPremiumFrom > policy.ValidTill)
            {
                throw new InvalidRiskRemovePeriodException("Can not remove risk as it's insurance period ends at the same month with policy");
            }

            var insurancePeriod               = new InsurancePeriod(calculateReturnedPremiumFrom, policy.ValidTill);
            var nonInsuredRiskPeriod          = new RiskInsurancePeriod(insurancePeriod, risk);
            var returnedPremiumForRemovedRisk = nonInsuredRiskPeriod.CalculatePremium();

            policy.Premium -= returnedPremiumForRemovedRisk;
            policy.InsuredRisks.Remove(risk);
        }