Esempio n. 1
0
        public async Task <IHttpActionResult> GetProductsInSubCategoryAsync(int subcategoryId)
        {
            using (var context = AdventureWorksProductContext.GetEagerContext())
            {
                var productSubcategory = await context.ProductSubcategories
                                         .Where(psc => psc.ProductSubcategoryId == subcategoryId)
                                         .FirstOrDefaultAsync();

                if (productSubcategory == null)
                {
                    // The subcategory was not found.
                    return(NotFound());
                }

                productSubcategory.Product = await context.Products
                                             .Where(p => subcategoryId == p.ProductSubcategoryId)
                                             .ToListAsync();

                foreach (var prod in productSubcategory.Product)
                {
                    int productId = prod.ProductId;

                    var productListPriceHistory = await context.ProductListPriceHistory
                                                  .Where(pl => pl.ProductId == productId)
                                                  .ToListAsync();

                    prod.ProductListPriceHistory = productListPriceHistory;
                }

                return(Ok(productSubcategory));
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> GetProductCategoryDetailsAsync(int subCategoryId)
        {
            using (var context = AdventureWorksProductContext.GetEagerContext())
            {
                var subCategory = await context.ProductSubcategories
                                  .Where(psc => psc.ProductSubcategoryId == subCategoryId)
                                  .Include("Product.ProductListPriceHistory")
                                  .FirstOrDefaultAsync();

                if (subCategory == null)
                {
                    return(NotFound());
                }

                return(Ok(subCategory));
            }
        }