public static decimal GetTotalStandardCostByCategory(ProductCategory category)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <decimal> result = db.Products.Where(product => product.ProductSubcategory.ProductCategory.Name.Equals(category.Name))
                                       .Select(product => product.StandardCost);
         return(result.Sum());
     }
 }
 public static string GetProductVendorByProductName(string productName)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <string> result = db.ProductVendors.Where(productVendor => productVendor.Product.Name.Equals(productName))
                                      .Select(productVendor => productVendor.Vendor.Name);
         return(result.Single());
     }
 }
 public static List <Product> GetProductsWithRecentReviews(int howManyReviews)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = db.ProductReviews.OrderByDescending(productReview => productReview.ReviewDate)
                                       .Select(productReview => productReview.Product);
         return(result.Take(howManyReviews).ToList());
     }
 }
 public static List <Product> GetProductsByName(String namePart)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = db.Products.Where(product => product.Name.Contains(namePart))
                                       .Select(product => product);
         return(result.ToList());
     }
 }
 public static List <string> GetProtuctNamesByVendorName(String vendorName)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <string> result = db.ProductVendors.Where(productVendor => productVendor.Vendor.Name.Equals(vendorName))
                                      .Select(productVendor => productVendor.Product.Name);
         return(result.ToList());
     }
 }
 public static List <Product> GetNProductsFromCategory(string categoryName, int n)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = db.Products.OrderByDescending(product => product.Name)
                                       .Where(product => product.ProductSubcategory.ProductCategory.Name.Equals(categoryName))
                                       .Select(product => product);
         return(result.Take(n).ToList());
     }
 }
 public static List <Product> GetProductsWithRecentReviews(int howManyReviews)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = from productReview in db.ProductReviews
                                       orderby productReview.ReviewDate descending
                                       select productReview.Product;
         return(result.Take(howManyReviews).ToList());
     }
 }
 public static decimal GetTotalStandardCostByCategory(ProductCategory category)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <decimal> result = from product in db.Products
                                       where product.ProductSubcategory.ProductCategory.Name.Equals(category.Name)
                                       select product.StandardCost;
         return(result.Sum());
     }
 }
 public static string GetProductVendorByProductName(string productName)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <string> result = from productVendor in db.ProductVendors
                                      where productVendor.Product.Name.Equals(productName)
                                      select productVendor.Vendor.Name;
         return(result.Single());
     }
 }
 public static List <string> GetProtuctNamesByVendorName(String vendorName)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <string> result = from productVendor in db.ProductVendors
                                      where productVendor.Vendor.Name.Equals(vendorName)
                                      select productVendor.Product.Name;
         return(result.ToList());
     }
 }
        public static List <Product> GetNRecentlyReviewedProductd(int howManyProducts)
        {
            using (ProductDataContext db = new ProductDataContext())
            {
                IQueryable <Product> result = db.Products.Join(db.ProductReviews, product => product.ProductID, review => review.ProductID, (product, review) => new { Product = product, Review = review })
                                              .OrderByDescending(review => review.Review.ReviewDate)
                                              .Select(product => product.Product);

                return(result.Take(howManyProducts).ToList());
            }
        }
        public static List <Product> GetProductsByName(String namePart)
        {
            using (ProductDataContext db = new ProductDataContext())
            {
                IQueryable <Product> result = from product in db.Products
                                              where product.Name.Contains(namePart)
                                              select product;

                return(result.ToList());
            }
        }
 public static List <Product> GetNProductsFromCategory(string categoryName, int n)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = from product in db.Products
                                       orderby product.Name descending
                                       where product.ProductSubcategory.ProductCategory.Name.Equals(categoryName)
                                       select product;
         return(result.Take(n).ToList());
     }
 }
 public static List <Product> GetNRecentlyReviewedProductd(int howManyProducts)
 {
     using (ProductDataContext db = new ProductDataContext())
     {
         IQueryable <Product> result = from product in db.Products
                                       join review in db.ProductReviews on product.ProductID equals review.ProductID
                                       orderby review.ReviewDate descending
                                       select product;
         return(result.Take(howManyProducts).ToList());
     }
 }