public IActionResult CreateShipment([FromBody] ShipmentToCreateDto shipmentToCreate) { try { if (shipmentToCreate == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var shipmentEntity = Mapper.Map <Shipment>(shipmentToCreate); _repo.AddShipment(shipmentEntity); if (!_repo.Save()) { throw new Exception("Error creating shipment."); } var shipmentToReturn = Mapper.Map <ShipmentDto>(shipmentEntity); return(CreatedAtRoute("GetShipment", new { id = shipmentToReturn.Id }, shipmentToReturn)); } catch (Exception ex) { throw new Exception(ex.Message); } }