Ejemplo n.º 1
0
        public Product EditProduct(string vendorCode, string name, string property, string description, decimal cost, bool isIngr, bool isMerch, byte measure,
                                   double cleanLoss, double fryLoss, double otherLosses,
                                   double protains, double fats, double carbohydrates, double energyCalorie, double energyJoule,
                                   Category category, Company manufacturer)
        {
            Product p = cont.Product.SingleOrDefault(pr => pr.IsExist && pr.VendorCode == vendorCode);

            if (cont.RecipeDishIngr.ToList().Exists(r => r.Ingredient == p) ||
                cont.RecipePrepIngr.ToList().Exists(r => r.Ingredient == p) ||
                cont.CheckMerchandise.ToList().Exists(r => r.Product == p))
            {
                IEnumerable <RecipeDishIngr> rdi = cont.RecipeDishIngr.ToList().FindAll(r => r.Dish.IsExist && r.Ingredient.IsExist && r.Ingredient.VendorCode == vendorCode);
                IEnumerable <RecipePrepIngr> rpi = cont.RecipePrepIngr.ToList().FindAll(r => r.Prepack.IsExist && r.Ingredient.IsExist && r.Ingredient.VendorCode == vendorCode);
                IEnumerable <Warehouse>      wh  = cont.Warehouse.ToList().FindAll(r => r.Product.VendorCode == vendorCode);

                p = AddProduct(p);

                List <Dish> dishes = new List <Dish>(rdi.Select(r => r.Dish)).Distinct().ToList();
                foreach (Dish d in dishes)
                {
                    Dish dish = new DishRepository(cont).AddDish(d);
                    foreach (RecipeDishIngr rd in cont.RecipeDishIngr.ToList().FindAll(r => r.Dish.Id == d.Id))
                    {
                        new RecipeDishIngrRepository(cont).AddRecipeDishIngr(rd.Volume, rd.Description, p, dish);
                    }
                }

                List <Prepack> results = new List <Prepack>(rpi.Select(r => r.Prepack)).Distinct().ToList();
                foreach (Prepack res in results)
                {
                    Prepack result = new PrepackRepository(cont).AddPrepack(res);
                    foreach (RecipePrepIngr rd in cont.RecipePrepIngr.ToList().FindAll(r => r.Prepack.Id == res.Id))
                    {
                        new RecipePrepIngrRepository(cont).AddRecipePrepIngr(rd.Volume, rd.Description, p, result);
                    }
                }

                foreach (Warehouse res in wh)
                {
                    Warehouse result = new WarehouseRepository(cont).AddWarehouse(res.InspectionDate.Value, res.FactualNumber.Value, res.Branch, p);
                }
            }
            else
            {
                p                    = cont.Product.SingleOrDefault(pr => pr.IsExist && pr.VendorCode == vendorCode);
                p.Name               = name;
                p.Property           = property;
                p.Description        = description;
                p.Cost               = cost;
                p.IsExist            = true;
                p.IsIngredient       = isIngr;
                p.IsMerchandise      = isMerch;
                p.Measure            = (Measure)measure;
                p.VendorCode         = vendorCode;
                p.LossDuringCleaning = cleanLoss;
                p.LossDuringFrying   = fryLoss;
                p.OtherLosses        = otherLosses;

                p.Energy = new EnergyValue
                {
                    Protains      = protains,
                    Fats          = fats,
                    Carbohydrates = carbohydrates,
                    EnergyCalorie = energyCalorie,
                    EnergyJoule   = energyJoule,
                };

                p.Category     = category;
                p.Manufacturer = manufacturer;
            }
            cont.SaveChanges();
            return(p);
        }
Ejemplo n.º 2
0
        public Prepack EditPrepack(string vendorCode, string name, string description, double finalVolume, byte measure,
                                   DateTime start, DateTime end,
                                   double cleanLoss, double fryLoss, double otherLosses,
                                   double protains, double fats, double carbohydrates, double energyCalorie, double energyJoule)
        {
            Prepack p = cont.Prepack.SingleOrDefault(pr => pr.IsExist && pr.VendorCode == vendorCode);

            if (cont.RecipeDishPrep.ToList().Exists(r => r.Prepack.Id == p.Id) ||
                cont.RecipePrepPrep.ToList().Exists(r => r.Prepack.Id == p.Id) ||
                cont.RecipePrepPrep.ToList().Exists(r => r.Result.Id == p.Id) ||
                cont.RecipePrepIngr.ToList().Exists(r => r.Prepack.Id == p.Id))
            {
                IEnumerable <RecipeDishPrep> rdp = cont.RecipeDishPrep.ToList().FindAll(r => r.Dish.IsExist && r.Prepack.IsExist && r.Prepack.VendorCode == vendorCode);
                IEnumerable <RecipePrepPrep> rrp = cont.RecipePrepPrep.ToList().FindAll(r => r.Result.IsExist && r.Prepack.IsExist && r.Prepack.VendorCode == vendorCode);
                IEnumerable <RecipePrepPrep> rpr = cont.RecipePrepPrep.ToList().FindAll(r => r.Result.IsExist && r.Prepack.IsExist && r.Result.VendorCode == vendorCode);
                IEnumerable <RecipePrepIngr> rpi = cont.RecipePrepIngr.ToList().FindAll(r => r.Ingredient.IsExist && r.Prepack.IsExist && r.Prepack.VendorCode == vendorCode);
                p = AddPrepack(p);

                List <Dish> dishes = new List <Dish>(rdp.Select(r => r.Dish)).Distinct().ToList();
                foreach (Dish d in dishes)
                {
                    Dish dish = new DishRepository(cont).AddDish(d);
                    foreach (RecipeDishPrep rd in cont.RecipeDishPrep.ToList().FindAll(r => r.Dish.Id == d.Id))
                    {
                        new RecipeDishPrepRepository(cont).AddRecipeDishPrep(rd.Volume, rd.Description, p, dish);
                    }
                }

                List <Prepack> results = new List <Prepack>(rrp.Select(r => r.Result)).Distinct().ToList();
                foreach (Prepack res in results)
                {
                    Prepack result = AddPrepack(res);
                    foreach (RecipePrepPrep rd in cont.RecipePrepPrep.ToList().FindAll(r => r.Result.Id == res.Id))
                    {
                        new RecipePrepPrepRepository(cont).AddRecipePrepPrep(rd.Volume, rd.Description, p, result);
                    }
                }

                foreach (RecipePrepPrep r in rpr)
                {
                    new RecipePrepPrepRepository(cont).AddRecipePrepPrep(r.Volume, r.Description, r.Prepack, p);
                }

                foreach (RecipePrepIngr r in rpi)
                {
                    new RecipePrepIngrRepository(cont).AddRecipePrepIngr(r.Volume, r.Description, r.Ingredient, p);
                }
            }
            else
            {
                p                    = cont.Prepack.SingleOrDefault(c => c.VendorCode.Equals(vendorCode));
                p.Name               = name;
                p.Description        = description;
                p.FinalVolume        = finalVolume;
                p.Measure            = (Measure)measure;
                p.CookStartTime      = start;
                p.CookEndTime        = end;
                p.LossDuringCleaning = cleanLoss;
                p.LossDuringFrying   = fryLoss;
                p.OtherLosses        = otherLosses;

                p.Energy = new EnergyValue
                {
                    Protains      = protains,
                    Fats          = fats,
                    Carbohydrates = carbohydrates,
                    EnergyCalorie = energyCalorie,
                    EnergyJoule   = energyJoule,
                };
            }
            cont.SaveChanges();
            return(p);
        }