/// <summary> /// Saves the shipment. /// </summary> /// <param name="shipment">The shipment.</param> /// <returns></returns> public static int SaveShipment(TDCShipment shipment) { try { // Make sure the shipment is valid if (shipment.IsValid) { // Save the shipment to the db and update the id, this will update the shipment lines if required shipment.Id = DataAccessProvider.Instance().SaveTDCShipment(shipment); // Get the checksum for the entity FrameworkController.GetChecksum(shipment, "Shipment"); // Save the shipment lines to the db foreach (TDCShipmentLine tdcShipmentLine in shipment.ShipmentLines) { // Save the shipment line and update the shipment line id if required tdcShipmentLine.Id = TDCShipmentLineController.SaveLine(tdcShipmentLine); } } else { // Entity is not valid throw new InValidBusinessObjectException(shipment); } } catch (Exception ex) { // Generate a new exception ex = new Exception( string.Format("Failed to save TDC shipment {0} - {1} for OpCo {2}. {3}", shipment.ShipmentNumber, shipment.DespatchNumber, shipment.OpCoCode, ex.Message)); // Log an throw if configured to do so if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw ex; } // We failed to save the shipment return(-1); } // Done return(shipment.Id); }