public async Task <Policy> CreatePolicy(Policy policy)
        {
            try
            {
                policy.PolicyId = null;
                if (CostRiskValidation.CostRiskValidator(policy))
                {
                    _context.Policies.Add(new Policy
                    {
                        Description        = policy.Description,
                        Name               = policy.Name,
                        PolicyCost         = policy.PolicyCost,
                        PolicyDateBegin    = policy.PolicyDateBegin,
                        PolicyId           = policy.PolicyId,
                        PolicyMonthsPeriod = policy.PolicyMonthsPeriod,
                        PolicyTypeId       = policy.PolicyTypeId,
                        RiskTypeId         = policy.RiskTypeId
                    });
                    await _context.SaveChangesAsync();
                }
            }
            catch (CostRiskException e)
            {
                throw e;
            }

            return(policy);
        }
Exemplo n.º 2
0
        public void RiskCostTest()
        {
            Policy policy = new Policy {
                RiskType = new RiskType {
                    Name = "Alto"
                }, PolicyType = new PolicyType {
                    PolicyCover = 0.7
                }
            };


            Assert.Throws <CostRiskException>(() => CostRiskValidation.CostRiskValidator(policy));
        }
        public async Task <Policy> UpdatePolicy(Policy policy)
        {
            try
            {
                if (CostRiskValidation.CostRiskValidator(policy))
                {
                    _context.Policies.Update(policy);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(policy);
        }