Beispiel #1
0
        public async Task <IActionResult> PostPolicy([FromBody] Policy policy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            RiskValidator oValidator = new RiskValidator(policy.RiskType, policy.Coverage);
            var           result     = oValidator.ValidateRisk();

            if (result == "OK")
            {
                _policyRepository.Add(policy);
                return(CreatedAtAction("GetPolicy", new { id = policy.Id }, policy));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> PutPolicy([FromRoute] int id, [FromBody] Policy policy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != policy.Id)
            {
                return(BadRequest());
            }

            RiskValidator oValidator = new RiskValidator(policy.RiskType, policy.Coverage);
            var           result     = oValidator.ValidateRisk();

            try
            {
                if (result == "OK")
                {
                    _policyRepository.Update(policy);
                }
                else
                {
                    return(Conflict(result));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PolicyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public void CanBeCancelledBy_Risk_ReturnsTrue()
        {
            var result = riskValidator.ValidateRisk();

            Assert.AreEqual("OK", "La cobertura esta bien");
        }