Example #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));
        }