Example #1
0
 public ActionResult <Insurance> Post([FromBody] Insurance insurance)
 {
     try
     {
         _insuranceService.Add(_insuranceService.CalculateInsuranceValue(insurance));
         return(Ok(insurance));
     }
     catch (Exception ex)
     {
         return(BadRequest($"Erro: {ex}"));
     }
 }
 public ActionResult Create(CreateInsurance createInsurance)
 {
     if (ModelState.IsValid)
     {
         _insuranceService.Add(createInsurance);
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(createInsurance));
     }
 }
        public ActionResult Create(CreateInsuranceViewModel createInsurance)
        {
            if (ModelState.IsValid)
            {
                Insurance insurance = _insuranceService.Add(createInsurance);
                if (insurance != null)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                ModelState.AddModelError("System", "Create failed.");
            }

            return(View(createInsurance));
        }
Example #4
0
        public IActionResult Insert([FromBody] Insurance insurance)
        {
            int addedId = _insuranceService.Add(insurance);

            if (addedId != default)
            {
                _insuranceAddingSender.SendInsurance(insurance);
                return(CreatedAtAction("FindOne", _insuranceService.Get(addedId)));
            }
            else
            {
                return(BadRequest());
            }
        }