Пример #1
0
        /// <summary>
        /// Saves the transactionSubType.
        /// </summary>
        /// <param name="transactionSubType">The transactionSubType.</param>
        /// <returns></returns>
        public static int SaveTransactionSubType(TransactionSubType transactionSubType)
        {
            try
            {
                if (transactionSubType.IsValid)
                {
                    // Save entity
                    transactionSubType.Id = DataAccessProvider.Instance().SaveTransactionSubType(transactionSubType);
                    if (transactionSubType.Id != -1)
                    {
                        FrameworkController.GetChecksum(transactionSubType);
                        CacheManager.Add(transactionSubType);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(transactionSubType);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(transactionSubType.Id);
        }
Пример #2
0
        /// <summary>
        /// Saves the warehouse.
        /// </summary>
        /// <param name="warehouse">The warehouse.</param>
        /// <returns></returns>
        public static int SaveWarehouse(Warehouse warehouse)
        {
            try
            {
                if (warehouse.IsValid)
                {
                    // Save entity
                    warehouse.Id = DataAccessProvider.Instance().SaveWarehouse(warehouse);
                    if (warehouse.Id != -1)
                    {
                        FrameworkController.GetChecksum(warehouse, "Warehouse");
                        CacheManager.Add(warehouse);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(warehouse);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(warehouse.Id);
        }
Пример #3
0
        /// <summary>
        /// Saves a route.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        public static int SaveRoute(Route route)
        {
            try
            {
                if (route.IsValid)
                {
                    route.Id = DataAccessProvider.Instance().SaveRoute(route);
                    if (route.Id != -1)
                    {
                        FrameworkController.GetChecksum(route);
                        CacheManager.Add(route, route.Warehouse != null);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(route);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(route.Id);
        }
Пример #4
0
        /// <summary>
        /// Saves the TDC shipment line.
        /// </summary>
        /// <param name="shipmentLine">The shipment line.</param>
        /// <returns></returns>
        public static int SaveLine(TDCShipmentLine shipmentLine)
        {
            try
            {
                // Make sure the shipment line is valid
                if (shipmentLine.IsValid)
                {
                    // Save the shipment line to the db
                    shipmentLine.Id = DataAccessProvider.Instance().SaveTDCShipmentLine(shipmentLine);

                    // Get the checksum for the entity
                    FrameworkController.GetChecksum(shipmentLine, "ShipmentLine");
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(shipmentLine);
                }
            }
            catch (Exception ex)
            {
                // Log an throw if configured to do so
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }

                // Failed
                return(-1);
            }

            // Done
            return(shipmentLine.Id);
        }
        /// <summary>
        /// Saves an OpCo Division object.
        /// </summary>
        /// <remarks>If the Id property =0 then an INSERT will Occur, otherwise an UPDATE will occur</remarks>
        /// <param name="opcoDivision">The opco.</param>
        /// <returns></returns>
        public static int SaveOpCoDivision(OpCoDivision opcoDivision)
        {
            try
            {
                if (opcoDivision.IsValid)
                {
                    // Save entity
                    opcoDivision.Id = DataAccessProvider.Instance().SaveOpCoDivision(opcoDivision);
                    if (opcoDivision.Id != -1)
                    {
                        FrameworkController.GetChecksum(opcoDivision);
                        CacheManager.Add(opcoDivision, opcoDivision.OpCo != null);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(opcoDivision);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(opcoDivision.Id);
        }
Пример #6
0
        /// <summary>
        /// Saves the specified SalesLocation to the underlying data store via the configured DataProvider.
        /// If the primary key (ID) of the supplied SalesLocation is Null, a new row is added to the underlying data store and a new primary key (ID) automatically generated.  If the primary key (ID) of the supplied SalesLocation has been specified, the existing row in the data store is updated if it has not already been altered.
        /// The primary key (ID) of the created or altered SalesLocation is returned to the caller.  If an error occurs, an exception is thrown and no updates made to the data store.
        /// For concurrency errors (the data has changed in-between load and save by an external system or user), a concurrency exception is thrown.
        /// </summary>
        /// <param name="salesLocation">The salesLocation.</param>
        /// <returns></returns>
        public static int SaveLocation(SalesLocation salesLocation)
        {
            try
            {
                if (salesLocation.IsValid)
                {
                    salesLocation.OpCo = OpcoController.GetOpCo(salesLocation.OpCoId, true);
                    // Save entity
                    salesLocation.Id = DataAccessProvider.Instance().SaveLocation(salesLocation);
                    if (salesLocation.Id != -1)
                    {
                        FrameworkController.GetChecksum(salesLocation);
                        CacheManager.Add(salesLocation, salesLocation.OpCo != null);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(salesLocation);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(salesLocation.Id);
        }
        /// <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);
        }