public static ShoppingBasketAddPageContent GetProductInStores(int nomenclatureId, int featuresSetId) { using (DBContext db = new DBContext()) { var entities = from A in db.NomenclatureInStores where (A.NomenclatureId == nomenclatureId && A.FeaturesSet == featuresSetId) join B in db.Stores on A.StoreId equals B.Id select new { StoreName = B.Name, StoreAddress = B.Address, Amount = A.Amount }; List <ProductInStore> productInStores = new List <ProductInStore>(); foreach (var item in entities) { ProductInStore productInStore = new ProductInStore(); productInStore.StoreName = item.StoreName; productInStore.StoreAddress = item.StoreAddress; productInStore.ProductAmount = item.Amount; productInStores.Add(productInStore); } ShoppingBasketAddPageContent product = new ShoppingBasketAddPageContent(); product.ProductName = db.Nomenclature.Find(nomenclatureId).Name.ToString(); product.ProductFeaturesSet = db.FeaturesSets.Find(featuresSetId).Name.ToString(); string path = AppDomain.CurrentDomain.BaseDirectory + @"/Content/nomenclature/pictures/"; string filename = db.NomenclatureViews.FirstOrDefault(x => x.NomenclatureId == nomenclatureId && x.FeaturesSetId == featuresSetId).Image.ToString() + "1.jpg"; product.ProductImage = filename; product.ProductInStores = productInStores; return(product); } }
public static ShoppingBasketAddPageContent GetProductInStores(int nomenclatureId, int featuresSetId) { using (DBContext db = new DBContext()) { var entities = from A in db.NomenclatureInStores where (A.NomenclatureId == nomenclatureId && A.FeaturesSet == featuresSetId) join B in db.Stores on A.StoreId equals B.Id select new { StoreName = B.Name, StoreAddress = B.Address, Amount = A.Amount }; List<ProductInStore> productInStores = new List<ProductInStore>(); foreach (var item in entities) { ProductInStore productInStore = new ProductInStore(); productInStore.StoreName = item.StoreName; productInStore.StoreAddress = item.StoreAddress; productInStore.ProductAmount = item.Amount; productInStores.Add(productInStore); } ShoppingBasketAddPageContent product = new ShoppingBasketAddPageContent(); product.ProductName = db.Nomenclature.Find(nomenclatureId).Name.ToString(); product.ProductFeaturesSet = db.FeaturesSets.Find(featuresSetId).Name.ToString(); string path = AppDomain.CurrentDomain.BaseDirectory + @"/Content/nomenclature/pictures/"; string filename = db.NomenclatureViews.FirstOrDefault(x => x.NomenclatureId == nomenclatureId && x.FeaturesSetId == featuresSetId).Image.ToString() + "1.jpg"; product.ProductImage = filename; product.ProductInStores = productInStores; return product; } }