Exemple #1
0
        static void priceDescending()
        {
            Thrift_ShopDataContext dbContext = new Thrift_ShopDataContext();

            var product = from Product in dbContext.Products
                          orderby Product.price descending
                          select Product;

            Console.WriteLine("Product Name     " + "Product Price     " + "Category     " + "Brand Name");
            foreach (Product p in product)
            {
                Console.WriteLine(p.name + "        " + p.price + "         " + p.category + "        " + p.Brand.brandName);
            }
        }
Exemple #2
0
        static void showProduct()
        {
            Thrift_ShopDataContext dbContext = new Thrift_ShopDataContext();
            IEnumerable <Product>  product   = from Product in dbContext.Products
                                               join Brand in dbContext.Brands
                                               on Product.brandID equals Brand.id into ID
                                               select Product;


            Console.WriteLine("Product Name     " + "Product Price     " + "Category     " + "Brand Name");
            foreach (Product p in product)
            {
                Console.WriteLine(p.name + "        " + p.price + "         " + p.category + "        " + p.Brand.brandName);
            }
        }
Exemple #3
0
        static void showBrand()
        {
            Thrift_ShopDataContext dbContext = new Thrift_ShopDataContext();

            var product = from Brand in dbContext.Brands
                          join Product in dbContext.Products
                          on Brand.id equals Product.brandID into ID
                          select new {
                name  = Brand.brandName,
                count = ID.Count(),
            };

            Console.WriteLine("Product Name" + "        " + "Numbers of products");
            foreach (var i in product)
            {
                Console.WriteLine(i.name + "        " + i.count);
            }
        }
Exemple #4
0
        static void addProduct()
        {
            String name, category, brandName;
            int    price;
            Thrift_ShopDataContext dbContext = new Thrift_ShopDataContext();
            int id = (from product in dbContext.Products
                      select product).Max(product => product.id);


            Console.WriteLine("Enter Product Name Product Price Category Brand Name");

            name      = Console.ReadLine();
            price     = int.Parse(Console.ReadLine());
            category  = Console.ReadLine();
            brandName = Console.ReadLine();

            int brandId = (from brand in dbContext.Brands
                           where brand.brandName == brandName
                           select brand.id).FirstOrDefault();

            while (brandId == 0)
            {
                Console.WriteLine("No such brand name Enter another one");

                brandName = Console.ReadLine();

                brandId = (from brand in dbContext.Brands
                           where brand.brandName == brandName
                           select brand.id).FirstOrDefault();
            }

            Product prod = new Product
            {
                id       = id + 1,
                name     = name,
                price    = price,
                category = category,
                brandID  = brandId
            };


            dbContext.Products.InsertOnSubmit(prod);
            dbContext.SubmitChanges();
        }
Exemple #5
0
        static void filterProduct()
        {
            double price;
            Thrift_ShopDataContext dbContext = new Thrift_ShopDataContext();

            Console.WriteLine("Enter price:");

            price = double.Parse(Console.ReadLine());

            var p = from product in dbContext.Products
                    where product.price <= price
                    select product;

            Console.WriteLine("Product Name" + "        " + "Product price");
            foreach (var i in p)
            {
                Console.WriteLine(i.name + "        " + i.price);
            }
        }