public ProductQrcodewithType GetByQrcode(string Qr, int user_id) { ProductQrcodewithType X = new ProductQrcodewithType(); X = _con.ProductQrcodes.Include(p => p.Types).FirstOrDefault(st => st.Qrcode == Qr); if (X != null) { if (_con.Stocks.FirstOrDefault(s => s.product == X) != null) { X.Stock(_con.Stocks.FirstOrDefault(s => s.product == X).Value); } for (int i = 0; i < X.Types.Count(); i++) { var test = _con.StocksOfType.FirstOrDefault(s => s.Type == X.Types[i]); if (test != null) { X.Stock(test.Value); } } } User U = new User(); U = _con.Users.Include(p => p.userClass).FirstOrDefault(st => st.ID == user_id); if (U != null) { var res = _con.StocksByClass.Include(p => p.products).FirstOrDefault(s => s._class == U.userClass); if (res != null) { if (res.products.FirstOrDefault(p => p == X) != null) { X.Stock(_con.StocksByClass.FirstOrDefault(s => s._class == U.userClass).Value); } } } /* * for (int i =0; i< _con.Stocks.Count(); i++) * { * if (_con.Stocks[i].product == X ) { X.Stock(_con.Stocks[i].Value); } * } * * for (int i = 0; i < _con.StocksOfType.Count(); i++) * { * for (int j = 0; j < X.Types.Count(); j++) * { * if (_con.StocksOfType[i].Type.name == X.Types[j] ) { X.Stock(_con.StocksOfType[i].Value); } * } * } */ return(X); }
public ProductQrcodewithType getbyID(int id, int user_id) { ProductQrcodewithType X = new ProductQrcodewithType(); X = _con.ProductQrcodes.Include(p => p.Image).Include(p => p.Types).FirstOrDefault(st => st.id == id); _con.ProductQrcodes.Where(p => p.Image == X.Image).Load(); if (X != null) { if (_con.Stocks.FirstOrDefault(s => s.product == X) != null) { X.Stock(_con.Stocks.FirstOrDefault(s => s.product == X).Value); } for (int i = 0; i < X.Types.Count(); i++) { var test = _con.StocksOfType.FirstOrDefault(s => s.Type == X.Types[i]); if (test != null) { X.Stock(test.Value); } } } User U = new User(); U = _con.Users.FirstOrDefault(st => st.ID == user_id); if (_con.StocksByClass.FirstOrDefault(s => s._class == U.userClass).products.FirstOrDefault(p => p == X) != null) { X.Stock(_con.StocksByClass.FirstOrDefault(s => s._class == U.userClass).Value); } /* * * * * for (int i = 0; i < _con.StocksOfType.Count(); i++) * { * for (int j = 0; j < X.Types.Count(); j++) * { * if (_con.StocksOfType[i].Type.name == X.Types[j] ) { X.Stock(_con.StocksOfType[i].Value); } * } * } */ return(X); }