public HttpResponseMessage AddCustomer(Customer customer)
        {
            if (string.IsNullOrWhiteSpace(customer.Name))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please fill in a name."));
            }

            _customerRepo.AddCustomer(customer);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        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."));
            }
        }
示例#3
0
        public async Task <ReturnDto <bool> > AddCustomer(Customer cust)
        {
            var rtn = new ReturnDto <bool>();

            if (cust == null)
            {
                rtn.ErrorCode    = ErrorCodes.OBJECT_NOT_PROVIDED;
                rtn.ReturnObject = false;

                return(rtn);
            }

            try
            {
                rtn.ReturnObject = await _custRepo.AddCustomer(cust);
            } catch (Exception e) {
                rtn.ErrorCode    = ErrorCodes.OTHER;
                rtn.ReturnObject = false;

                _logger.LogError($"An error occured in - {typeof(CustomerService)} - Add Customer - Message: {e.Message} - C: {cust.CustomerGuid}, U: {cust.UserGuid}");
            }

            return(rtn);
        }
示例#4
0
 public void AddCustomer(Customer customer)
 {
     custRepo.AddCustomer(customer);
 }
示例#5
0
 public void AddCustomer(Customer newCustomer)
 {
     _customerRepo.AddCustomer(newCustomer);
 }
 public bool Post(Customers customer)
 {
     customerRepo.AddCustomer(customer);
     return(true);
 }
示例#7
0
 /// <summary>
 /// Adds customer
 /// </summary>
 /// <param name="newCustomer"></param>
 public void AddCustomer(Customer newCustomer)
 {
     repo.AddCustomer(newCustomer);  //TODO: check for duplicate customers
     Log.Information("New customer signed up.");
 }