public ActionResult <Customer> Post([FromBody] Customer customer)
        {
            try
            {
                if (_customerRepo.CustomerExists(customer))
                {
                    return(BadRequest("customer already exists."));
                }

                var customerId = _customerRepo.AddCustomer(customer);
                if (customerId != 0)
                {
                    return(Created($"api/customers/getcustomerbyid/{customerId}", customer));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(this.StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, "Unexpected database error."));
            }
        }
Beispiel #2
0
 private bool CustomerExists(int id)
 {
     return(_context.CustomerExists(id));
 }