/// <summary> /// Updates the shipment status if business rules allow it. /// </summary> /// <param name="shipmentToUpdate">The shipment to update.</param> /// <param name="newStatus">The new status.</param> /// <param name="updatedBy">The updated by.</param> /// <returns></returns> public static bool UpdateShipmentStatus(TDCShipment shipmentToUpdate, Shipment.StatusEnum newStatus, string updatedBy) { bool success = false; try { bool update = false; switch (newStatus) { case Shipment.StatusEnum.Mapped: { if (shipmentToUpdate.Status == Shipment.StatusEnum.Routing) { update = true; } break; } case Shipment.StatusEnum.Routing: { if (shipmentToUpdate.Status == Shipment.StatusEnum.Mapped) { update = true; } break; } default: { throw new Exception( string.Format("Cannot change status from {0} to {1}, it breaks business rules", shipmentToUpdate.Status.ToString(), newStatus.ToString())); } } if (update) { // Update the status of the shipment in the db success = DataAccessProvider.Instance().UpdateTDCShipmentStatus(shipmentToUpdate, newStatus, updatedBy); if (!success) { throw new Exception("Failed to Update Status."); } } } catch (Exception ex) { // Log an throw if configured to do so if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } return(success); }
//public static void UpdateShipmentStatus(OpCoShipment shipment) //{ // try // { // // Get an instance of the data access provider // DataAccessProvider dataAccessProvider = DataAccessProvider.Instance(); // // Update the status of the opco shipment in the db // dataAccessProvider.UpdateOpCoShipmentStatus(shipment); // } // catch (Exception ex) // { // // Log an throw if configured to do so // if (ExceptionPolicy.HandleException(ex, "Business Logic")) throw; // } //} /// <summary> /// Updates the status for all shipments, if any fail then the transaction is rolled back. /// </summary> /// <param name="shipments">The shipments.</param> /// <param name="newStatus">The new status.</param> /// <param name="updatedBy">The updated by.</param> /// <returns></returns> public static bool UpdateShipmentStatus(List <TDCShipment> shipments, Shipment.StatusEnum newStatus, string updatedBy) { using (TransactionScope scope = new TransactionScope()) { foreach (TDCShipment shipment in shipments) { if (!UpdateShipmentStatus(shipment, newStatus, updatedBy)) { return(false); } } if (Transaction.Current != null && Transaction.Current.TransactionInformation.Status == TransactionStatus.Active) { scope.Complete(); } } return(true); }