public void CreateProdGroup(ProductGroupBM model)
        {
            ProdGroup element = context.ProdGroups.FirstOrDefault(rec => rec.Name == model.Name);

            if (element != null)
            {
                throw new Exception("Уже есть группа с таким name");
            }
            context.ProdGroups.Add(new ProdGroup
            {
                Name = model.Name,
                Norm = model.Norm
            });
            context.SaveChanges();
        }
        public ProductGroupBM GetElement(int id)
        {
            ProdGroup element = context.ProdGroups.FirstOrDefault(rec => rec.Id == id);

            if (element != null)
            {
                return(new ProductGroupBM
                {
                    Id = element.Id,
                    Name = element.Name,
                    Norm = element.Norm,
                    Products = element.Products
                });
            }
            throw new Exception("Элемент не найден");
        }
Example #3
0
        public List <ProductBM> Less()
        {
            List <ProductBM> result   = new List <ProductBM>();
            List <WaybillBM> waybills = context.Waybills.Select(rec => new WaybillBM
            {
                Id = rec.Id,
                TypeOfWaybillId = rec.TypeOfWaybillId
            }).ToList();

            List <ProductBM> products = context.Products.Select(rec => new ProductBM
            {
                Id          = rec.Id,
                ProdGroupId = rec.ProdGroupId,
                Name        = rec.Name,
                Mark        = rec.Mark,
                Producer    = rec.Producer,
                Provider    = rec.Provider,
                Price       = rec.Price,
                AdvInf      = rec.AdvInf,
                Number      = rec.Number
            }).ToList();

            double SumProdictsOld = 0;
            double SumProdictsNew = 0;

            foreach (ProductBM prod in products)
            {
                int       haves = 0;
                ProdGroup pg    = context.ProdGroups.FirstOrDefault(rec => rec.Id == prod.ProdGroupId);
                int       norm  = pg.Norm;

                foreach (WaybillBM wb in waybills)
                {
                    if (wb.TypeOfWaybillId == 2)
                    {
                        List <ProductWaybillBM> productWaybills = context.ProductWaybills.Select(rec => new ProductWaybillBM
                        {
                            Id        = rec.Id,
                            ProductId = rec.ProductId,
                            WaybillId = rec.WaybillId,
                            Count     = rec.Count
                        }).Where(rec => rec.WaybillId == wb.Id & rec.ProductId == prod.Id)
                                                                  .ToList();

                        foreach (ProductWaybillBM p in productWaybills)
                        {
                            haves += p.Count;
                        }
                    }

                    if (wb.TypeOfWaybillId == 3 || wb.TypeOfWaybillId == 4)
                    {
                        List <ProductWaybillBM> productWaybills = context.ProductWaybills.Select(rec => new ProductWaybillBM
                        {
                            Id        = rec.Id,
                            ProductId = rec.ProductId,
                            WaybillId = rec.WaybillId,
                            Count     = rec.Count
                        }).Where(rec => rec.WaybillId == wb.Id & rec.ProductId == prod.Id)
                                                                  .ToList();

                        foreach (ProductWaybillBM p in productWaybills)
                        {
                            haves -= p.Count;
                        }
                    }
                }
                if (haves < norm)
                {
                    result.Add(prod);
                }
            }
            return(result);
        }