public IActionResult Post([FromBody] ArtOrderViewModel model) { // Post(ArtOrder model) from querystring // return Ok(); try { if (ModelState.IsValid) { //var newArtOrder = new ArtOrder() //{ // OrderDate = model.OrderDate, // OrderNumber = model.OrderNumber, // Id = model.OrderId //}; var newArtOrder = mapper.Map <ArtOrderViewModel, ArtOrder>(model); if (newArtOrder.OrderDate == DateTime.MinValue) { newArtOrder.OrderDate = DateTime.Now; } repository.AddEntity(newArtOrder); if (repository.SaveAll()) { //var vm = new ArtOrderViewModel() //{ // OrderId = newArtOrder.Id, // OrderDate = newArtOrder.OrderDate, // OrderNumber = newArtOrder.OrderNumber //}; //return Created($"/api/orders/{vm.OrderId}", vm); return(Created($"/api/orders/{newArtOrder.Id}", mapper.Map <ArtOrder, ArtOrderViewModel>(newArtOrder))); } } else { return(BadRequest(ModelState)); } } catch (Exception ex) { logger.LogError($"Failed to save new order: {ex}"); } return(BadRequest("Failed to save new order")); }