示例#1
0
        public async Task <ActionResult> New(CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _service.Insert(creditCard);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (ModelValidationException e)
                {
                    ModelState.AddModelError("CreditCardError", e.Message);
                    return(View(creditCard));
                }
                catch (DbUpdateException e)
                {
                    TempData["ErrorMessage"] = e.Message;
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
                }
            }
            else
            {
                return(View(creditCard));
            }
        }
 public IHttpActionResult AddCreditCard(CreditCard obj)
 {
     try
     {
         _service.Insert(obj);
         return(Ok());
     }
     catch (ObjectAlreadyExistsException e)
     {
         return(BadRequest(e.Message));
     }
 }