public IActionResult PostClient([FromBody] ClientEntityModel model) { try { if (ModelState.IsValid) { var newClient = _mapper.Map <ClientEntityModel, Client>(model); _repo.AddClient(newClient); if (_repo.SaveAll()) { return(Created($"/api/orders/{newClient.Id}", _mapper.Map <Client, ClientEntityModel>(newClient))); } } else { _logger.LogError($"Failed to post client with wrong model: {ModelState}"); return(BadRequest(ModelState)); } } catch (Exception e) { _logger.LogError($"Failed to post client: {e}"); } return(BadRequest(("Failed to save new client"))); }