Ejemplo n.º 1
0
        public async Task <IHttpActionResult> CreateCustomer([FromBody] Customer customer)
        {
            ErrorLog error = new ErrorLog();

            if (customer.FullName == null)
            {
                string message = "no items to add in the database";
                error.WriteErrorLog(message);
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NoContent, message));
            }
            try
            {
                var customerresult = await db.CreateCustomer(customer);

                if (customerresult != null)
                {
                    return(Ok(customerresult));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                error.WriteErrorLog(ex.Message);
                return(BadRequest());
            }
        }