Beispiel #1
0
        public async Task <IActionResult> CreateCustomer([FromBody] CustomerForCreation customer)
        {
            var customerEntity = _mapper.Map <Customer>(customer);

            var search = _customersRepository.CheckCustomerExists(customerEntity);

            if (search != null)
            {
                return(BadRequest("Customer already exists"));
            }

            _customersRepository.AddCustomer(customerEntity);

            await _customersRepository.SaveChangesAsync();

            await _customersRepository.GetCustomerAsync(customerEntity.Id);

            return(CreatedAtRoute("GetCustomer",
                                  new { id = customerEntity.Id },
                                  customerEntity));
        }
Beispiel #2
0
 /// <summary>
 /// Adds a new customer
 /// </summary>
 /// <param name="customer">The customer object to add</param>
 /// <returns>The customer object after adding to the account.</returns>
 public ApiResult <Customer> AddCustomer(CustomerForCreation customer)
 {
     return(post <ApiResult <Customer> >($"/customers", customer));
 }