Esempio n. 1
0
        public RiskInsurancePeriod(InsurancePeriod insurancePeriod, Risk risk)
        {
            if (insurancePeriod == null)
            {
                throw new ArgumentNullException(nameof(insurancePeriod));
            }

            this.insurancePeriod = insurancePeriod;
            this.risk            = risk;

            RiskName = risk.Name;
        }
Esempio n. 2
0
        public InitialRiskSet(IList <Risk> insuredRisks, InsurancePeriod insurancePeriod, params RiskInsurancePeriod[] additionalInsuredPeriods)
        {
            if (insurancePeriod == null)
            {
                throw new ArgumentNullException(nameof(insurancePeriod));
            }
            if (insuredRisks == null || !insuredRisks.Any())
            {
                throw new MissingInitialInsuredRisksException("Missing initial Insured Risks");
            }

            this.insuredRisks = insuredRisks.ToDictionary(
                r => r.Name, r => new RiskInsurancePeriod(insurancePeriod, r));

            foreach (var additionalInsuredPeriod in additionalInsuredPeriods)
            {
                this.insuredRisks.Add(additionalInsuredPeriod.RiskName, additionalInsuredPeriod);
            }
        }
Esempio n. 3
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);
        }
 private IEnumerable <Policy> GetEffectivePolicies(string nameOfInsuredObject, InsurancePeriod insurancePeriod)
 {
     return(policyRepository.FindByNameOfInsuredObject(nameOfInsuredObject)
            .Where(p => p.OverlapsWith(insurancePeriod)));
 }