/// <summary>
 /// Create a new DSLToolComplemarTranslation object.
 /// </summary>
 /// <param name="cOMETOrderId">Initial value of the COMETOrderId property.</param>
 /// <param name="dSLToolOrderId">Initial value of the DSLToolOrderId property.</param>
 /// <param name="timeCollected">Initial value of the TimeCollected property.</param>
 public static DSLToolComplemarTranslation CreateDSLToolComplemarTranslation(global::System.Int32 cOMETOrderId, global::System.String dSLToolOrderId, global::System.DateTime timeCollected)
 {
     DSLToolComplemarTranslation dSLToolComplemarTranslation = new DSLToolComplemarTranslation();
     dSLToolComplemarTranslation.COMETOrderId = cOMETOrderId;
     dSLToolComplemarTranslation.DSLToolOrderId = dSLToolOrderId;
     dSLToolComplemarTranslation.TimeCollected = timeCollected;
     return dSLToolComplemarTranslation;
 }
Ejemplo n.º 2
0
        private void ProcessCOMETOrderStatuses(IEnumerable<OrderStatus> orderStatusList, out int numOrders)
        {
            Console.WriteLine("Begin processing COMET Order status list...");
            numOrders = 0;

            using (var db = new Order_Entities())
            {
                // check for any FI orders that don't yet have VendorOrderIDs but which have DSL Tool order IDs
                var ordersLackingVendorIDs = db.Orders.Where(o => !string.IsNullOrEmpty(o.DSLToolOrderId) && string.IsNullOrEmpty(o.VendorOrderId)).ToList();

                // get the list of current lookup records it the DSLToolComplemar lookup table
                var existingCometOrderIds = db.DSLToolComplemarTranslations.Select(d => d.COMETOrderId).ToList();

                foreach (var status in orderStatusList.Where(status => status.CustomerID.Substring(0, 2) == "FI"))
                {
                    Console.WriteLine("Processing order: " + status.CustomerID);
                    var dataChanged = false;

                    // see if the COMET order ID already exists in the lookup table
                    var existsInLookupTable = existingCometOrderIds.Contains(status.Transaction);

                    // see if the DSL Order Tool order number already exists in the order record
                    // (the DSL Order Tool order number is represented as the CustomerID in Complemar's database)
                    var myOrder = ordersLackingVendorIDs.FirstOrDefault(o => o.DSLToolOrderId == status.CustomerID);
                    if (myOrder != null)
                    {
                        // if it does, insert the COMET order id value
                        myOrder.VendorOrderId = status.Transaction.ToString(CultureInfo.InvariantCulture);
                        dataChanged = true;
                    }

                    // if dataChanged, we don't need a lookup record anymore...all the needed data is in the order record
                    // so, if !existsInLookupTable and dataChanged, do nothing
                    // if existsInLookupTable and dataChanged), remove the existing entry (there is no more updating needing to be done, ever)
                    // if !existsInLookupTable and !dataChanged, add a new entry (we have no record of the DSL Tool order ID, so save the lookup record)
                    // if existsInLookupTable and !dataChanged, do nothing
                    if (!existsInLookupTable && !dataChanged)
                    {
                        var newEntry = new DSLToolComplemarTranslation();
                        newEntry.COMETOrderId = status.Transaction;
                        newEntry.DSLToolOrderId = status.CustomerID;
                        newEntry.TimeCollected = DateTime.Now;
                        db.DSLToolComplemarTranslations.AddObject(newEntry);
                        dataChanged = true;
                    }
                    else if (existsInLookupTable && dataChanged)
                    {
                        db.DSLToolComplemarTranslations.DeleteObject(db.DSLToolComplemarTranslations.First(d => d.COMETOrderId == status.Transaction));
                    }

                    // save changes to the db
                    if (dataChanged)
                    {
                        db.SaveChanges();
                    }
                    numOrders++;
                }
            }
            Console.WriteLine("Done processing.");
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the DSLToolComplemarTranslations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDSLToolComplemarTranslations(DSLToolComplemarTranslation dSLToolComplemarTranslation)
 {
     base.AddObject("DSLToolComplemarTranslations", dSLToolComplemarTranslation);
 }