public IActionResult Post([FromBody] CarViewModel model) { try { if (ModelState.IsValid) { var newCar = mapper.Map <CarViewModel, Car>(model); db.AddEntity(newCar); db.SaveAll(); return(Created($"/api/cars/{newCar.Id}", mapper.Map <Car, CarViewModel>(newCar))); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { logger.LogError($"Failed to save the car: {ex}"); } return(BadRequest("Failed to save the car")); }