public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var productionBatchKey = getInput();

            var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(productionBatchKey,
                                                                                 b => b.Production.Results,
                                                                                 b => b.Production.ResultingChileLot.Lot,
                                                                                 b => b.PackSchedule.PackagingProduct.Product,
                                                                                 b => b.PackSchedule.ChileProduct.Product,
                                                                                 b => b.PackSchedule.ProductionLineLocation,
                                                                                 b => b.PackSchedule.ProductionBatches.Select(p => p.Production.PickedInventory));

            if (productionBatch == null)
            {
                throw new Exception(string.Format("ProductionBatch[{0}] not found.", productionBatchKey));
            }

            var lotNumber = LotNumberBuilder.BuildLotNumber(productionBatch);
            var lot       = OldContext.tblLots.FirstOrDefault(l => l.Lot == lotNumber);

            if (lot == null)
            {
                throw new Exception(string.Format("tblLot[{0}] not found.", lotNumber));
            }
            UpdateLot(lot, productionBatch);

            var oldPackSchedule = OldContext.tblPackSches.FirstOrDefault(p => p.PackSchID == productionBatch.PackSchedule.PackSchID);

            if (oldPackSchedule == null)
            {
                throw new Exception(string.Format("tblPackSch[{0}] could not be found.", productionBatch.PackSchedule.PackSchID));
            }
            oldPackSchedule.Serialized = SerializablePackSchedule.Serialize(productionBatch.PackSchedule);

            var serialized = new SerializedData(OldContext);

            serialized[SerializableType.ChileLotProduction, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production);
            if (productionBatch.Production.Results != null)
            {
                serialized[SerializableType.LotProductionResults, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production.Results);
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.UpdatedLot, lot.Lot);
        }
        public static void SynchronizeOldContextPackSchedule(tblPackSch oldPackSchedule, PackSchedule newPackSchedule)
        {
            int chileProdId;

            if (!Int32.TryParse(newPackSchedule.ChileProduct.Product.ProductCode, out chileProdId))
            {
                throw new Exception(String.Format("Could not parse chile ProdID[{0}]", newPackSchedule.ChileProduct.Product.ProductCode));
            }

            oldPackSchedule.EmployeeID         = newPackSchedule.EmployeeId;
            oldPackSchedule.ProductionDeadline = newPackSchedule.ProductionDeadline.GetDate();
            oldPackSchedule.PackSchDate        = newPackSchedule.ScheduledProductionDate.Date;

            oldPackSchedule.ProdID         = chileProdId;
            oldPackSchedule.PackSchDesc    = newPackSchedule.SummaryOfWork;
            oldPackSchedule.BatchTypeID    = (int?)BatchTypeIDHelper.GetBatchTypeID(newPackSchedule.WorkType.Description);
            oldPackSchedule.ProductionLine = GetProductionLine(newPackSchedule.ProductionLineLocation.Description);

            oldPackSchedule.TargetWgt = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetWeight;
            oldPackSchedule.TgtAsta   = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetAsta;
            oldPackSchedule.TgtScan   = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetScan;
            oldPackSchedule.TgtScov   = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetScoville;

            oldPackSchedule.OrderNumber = newPackSchedule.OrderNumber;
            oldPackSchedule.Company_IA  = newPackSchedule.Customer == null ? null : newPackSchedule.Customer.Company.Name;

            if (oldPackSchedule.tblLots != null)
            {
                foreach (var lot in oldPackSchedule.tblLots)
                {
                    lot.ProdID         = oldPackSchedule.ProdID;
                    lot.ProductionDate = oldPackSchedule.PackSchDate;
                    lot.BatchTypeID    = oldPackSchedule.BatchTypeID;
                    lot.Company_IA     = oldPackSchedule.Company_IA;
                    lot.ProductionLine = oldPackSchedule.ProductionLine;
                }
            }

            oldPackSchedule.Serialized = SerializablePackSchedule.Serialize(newPackSchedule);
        }