public IActionResult AddCustomer([FromBody] CustomerDto customerDtoToSave) { if (customerDtoToSave == null) { return(BadRequest("customerDtoToSave is null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Customer customerToSave = AutoMapper.Mapper.Map <Customer>(customerDtoToSave); _customerRepository.Add(customerToSave); bool result = _customerRepository.Save(); if (!result) { //return new StatusCodeResult(500); throw new Exception($" ----> AddCustomer() {customerDtoToSave.ToString()}"); } //return Ok(AutoMapper.Mapper.Map<CustomerDto>(customerToSave)); return(CreatedAtRoute("GetSingleCustomer", new { id = customerToSave.Id }, AutoMapper.Mapper.Map <CustomerDto>(customerToSave))); }