示例#1
0
        private tblProduct SyncChileProduct(Product product, List <AdditiveTypeKey> deletedIngredients)
        {
            var chileProduct = UnitOfWork.ChileProductRepository.FindByKey(product.ToProductKey(),
                                                                           c => c.ProductAttributeRanges,
                                                                           c => c.Ingredients);

            tblProduct oldProduct;
            int        prodId;
            var        syncIngredients = new SyncChileProductHelper(OldContext);

            if (int.TryParse(product.ProductCode, out prodId))
            {
                oldProduct = syncIngredients.GetProduct(prodId);
            }
            else
            {
                throw new Exception("OldContextSync - ProductCode must be numeric.");
            }

            if (oldProduct == null)
            {
                oldProduct = new tblProduct
                {
                    ProdID          = prodId,
                    ProdGrpID       = chileProduct.ChileTypeId,
                    PTypeID         = (int)chileProduct.ChileState,
                    EmployeeID      = 100,
                    EntryDate       = DateTime.Now,
                    TrtmtID         = StaticInventoryTreatments.NoTreatment.Id,
                    tblProductIngrs = new EntityCollection <tblProductIngr>(),
                    s_GUID          = Guid.NewGuid()
                };
                OldContext.tblProducts.AddObject(oldProduct);
            }

            oldProduct.Product  = product.Name;
            oldProduct.InActive = !product.IsActive;
            oldProduct.Mesh     = (decimal?)chileProduct.Mesh;
            oldProduct.IngrDesc = chileProduct.IngredientsDescription;

            SetChileProductSpec(chileProduct, oldProduct);
            syncIngredients.SyncIngredients(chileProduct, oldProduct, deletedIngredients);

            return(oldProduct);
        }
示例#2
0
        public override void Synchronize(Func <SyncProductParameters> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var parameters   = getInput();
            var chileProduct = UnitOfWork.ChileProductRepository.FindByKey(parameters.ProductKey,
                                                                           c => c.Product,
                                                                           c => c.Ingredients);

            var syncIngredients = new SyncChileProductHelper(OldContext);
            var prodId          = int.Parse(chileProduct.Product.ProductCode);

            var oldProduct = syncIngredients.GetProduct(prodId);

            syncIngredients.SyncIngredients(chileProduct, oldProduct, parameters.DeletedIngredients);

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.SynchedTblProduct, prodId);
        }