Beispiel #1
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            dataMapper dataMapper = new dataMapper();
            var        Categories = dataMapper.GetAllCategories();
            var        Products   = dataMapper.GetAllProducts();
            var        Orders     = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            var mostExpProducts = Products
                                  .OrderByDescending(p => p.UnitPrice)
                                  .Take(5)
                                  .Select(p => p.Name);

            Console.WriteLine(string.Join(Environment.NewLine, mostExpProducts));

            Console.WriteLine(new string('-', 10));

            // Number of products in each Category
            var numberProdCategory = Products
                                     .GroupBy(p => p.Category_ID)
                                     .Select(grp => new { Category = Categories.First(c => c.ID == grp.Key).Name, Count = grp.Count() })
                                     .ToList();

            foreach (var item in numberProdCategory)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

            Console.WriteLine(new string('-', 10));

            // The 5 top products (by Order quantity)
            var topProducts = Orders
                              .GroupBy(o => o.Product_ID)
                              .Select(grp => new { Product = Products.First(p => p.ID == grp.Key).Name, Quantities = grp.Sum(grpgrp => grpgrp.Quantity) })
                              .OrderByDescending(q => q.Quantities)
                              .Take(5);

            foreach (var item in topProducts)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

            Console.WriteLine(new string('-', 10));

            // The most profitable Category
            var profitableCategory = Orders
                                     .GroupBy(o => o.Product_ID)
                                     .Select(g => new { catId = Products.First(p => p.ID == g.Key).Category_ID, price = Products.First(p => p.ID == g.Key).UnitPrice, quantity = g.Sum(p => p.Quantity) })
                                     .GroupBy(gg => gg.catId)
                                     .Select(grp => new { category_name = Categories.First(c => c.ID == grp.Key).Name, total_quantity = grp.Sum(g => g.quantity * g.price) })
                                     .OrderByDescending(g => g.total_quantity)
                                     .First();

            Console.WriteLine("{0}: {1}", profitableCategory.category_name, profitableCategory.total_quantity);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var mp  = new dataMapper();
            var _   = mp.getAllCategories();
            var __  = mp.getAllProducts();
            var ___ = mp.getAllOrders();

            // Names of the 5 most expensive products
            var first = __
                        .OrderByDescending(p => p.unit_price)
                        .Take(5)
                        .Select(p => p.nome);

            Console.WriteLine(string.Join(Environment.NewLine, first));

            Console.WriteLine(new string('-', 10));

            // Number of products in each category
            var second = __
                         .GroupBy(p => p.catId)
                         .Select(grp => new { Category = _.First(c => c.Id == grp.Key).NAME, Count = grp.Count() })
                         .ToList();

            foreach (var item in second)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

            Console.WriteLine(new string('-', 10));

            // The 5 top products (by order quantity)
            var third = ___
                        .GroupBy(o => o.product_id)
                        .Select(grp => new { Product = __.First(p => p.id == grp.Key).nome, Quantities = grp.Sum(grpgrp => grpgrp.quant) })
                        .OrderByDescending(q => q.Quantities)
                        .Take(5);

            foreach (var item in third)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

            Console.WriteLine(new string('-', 10));

            // The most profitable category
            var category = ___
                           .GroupBy(o => o.product_id)
                           .Select(g => new { catId = __.First(p => p.id == g.Key).catId, price = __.First(p => p.id == g.Key).unit_price, quantity = g.Sum(p => p.quant) })
                           .GroupBy(gg => gg.catId)
                           .Select(grp => new { category_name = _.First(c => c.Id == grp.Key).NAME, total_quantity = grp.Sum(g => g.quantity * g.price) })
                           .OrderByDescending(g => g.total_quantity)
                           .First();

            Console.WriteLine("{0}: {1}", category.category_name, category.total_quantity);
        }
Beispiel #3
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new dataMapper();
            var categories = dataMapper.getAllCategories();
            var products   = dataMapper.getAllProducts();
            var orders     = dataMapper.getAllOrders();

            var fiveMostExpensiveProducts = products
                                            .OrderByDescending(p => p.UnitPrice)
                                            .Take(5)
                                            .Select(p => p.Name);

            Console.WriteLine(string.Join(Environment.NewLine, fiveMostExpensiveProducts));
            Console.WriteLine(new string('-', 10));

            var countOfProductsInCategories = products
                                              .GroupBy(product => product.CategoryID)
                                              .Select(group => new { Category = categories.First(cat => cat.Id == group.Key)
                                                                                .Name, Count = group.Count() })
                                              .ToList();

            foreach (var item in countOfProductsInCategories)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

            Console.WriteLine(new string('-', 10));

            var topProductsByOrderQuantity = orders
                                             .GroupBy(order => order.ProductId)
                                             .Select(group => new { Product = products.First(product => product.Id == group.Key)
                                                                              .Name, Quantities = group.Sum(count => count.Quantity) })
                                             .OrderByDescending(quantity => quantity.Quantities)
                                             .Take(5);

            foreach (var item in topProductsByOrderQuantity)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

            Console.WriteLine(new string('-', 10));

            var mostProfitableCategory = orders
                                         .GroupBy(order => order.ProductId)
                                         .Select(group => new { catId = products.First(product => product.Id == group.Key)
                                                                        .CategoryID, price = products.First(product => product.Id == group.Key)
                                                                                             .UnitPrice, quantity = group.Sum(product => product.Quantity) })
                                         .GroupBy(category => category.catId)
                                         .Select(group => new { category_name = categories.First(category => category.Id == group.Key).Name, total_quantity = group.Sum(grp => grp.quantity * grp.price) })
                                         .OrderByDescending(group => group.total_quantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.category_name, mostProfitableCategory.total_quantity);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            dataMapper dataMapper = new dataMapper();
            var Categories = dataMapper.GetAllCategories();
            var Products = dataMapper.GetAllProducts();
            var Orders = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            var mostExpProducts = Products
                .OrderByDescending(p => p.UnitPrice)
                .Take(5)
                .Select(p => p.Name);
            Console.WriteLine(string.Join(Environment.NewLine, mostExpProducts));

            Console.WriteLine(new string('-', 10));

            // Number of products in each Category
            var numberProdCategory = Products
                .GroupBy(p => p.Category_ID)
                .Select(grp => new { Category = Categories.First(c => c.ID == grp.Key).Name, Count = grp.Count() })
                .ToList();
            foreach (var item in numberProdCategory)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

            Console.WriteLine(new string('-', 10));

            // The 5 top products (by Order quantity)
            var topProducts = Orders
                .GroupBy(o => o.Product_ID)
                .Select(grp => new { Product = Products.First(p => p.ID == grp.Key).Name, Quantities = grp.Sum(grpgrp => grpgrp.Quantity) })
                .OrderByDescending(q => q.Quantities)
                .Take(5);
            foreach (var item in topProducts)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

            Console.WriteLine(new string('-', 10));

            // The most profitable Category
            var profitableCategory = Orders
                .GroupBy(o => o.Product_ID)
                .Select(g => new { catId = Products.First(p => p.ID == g.Key).Category_ID, price = Products.First(p => p.ID == g.Key).UnitPrice, quantity = g.Sum(p => p.Quantity) })
                .GroupBy(gg => gg.catId)
                .Select(grp => new { category_name = Categories.First(c => c.ID == grp.Key).Name, total_quantity = grp.Sum(g => g.quantity * g.price) })
                .OrderByDescending(g => g.total_quantity)
                .First();
            Console.WriteLine("{0}: {1}", profitableCategory.category_name, profitableCategory.total_quantity);
        }
Beispiel #5
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var mp = new dataMapper();
            var _ = mp.getAllCategories();
            var __ = mp.getAllProducts();
            var ___ = mp.getAllOrders();

            // Names of the 5 most expensive products
            var first = __
                .OrderByDescending(p => p.unit_price)
                .Take(5)
                .Select(p => p.nome);
            Console.WriteLine(string.Join(Environment.NewLine, first));

            Console.WriteLine(new string('-', 10));

            // Number of products in each category
            var second = __
                .GroupBy(p => p.catId)
                .Select(grp => new { Category = _.First(c => c.Id == grp.Key).NAME, Count = grp.Count() })
                .ToList();
            foreach (var item in second)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

            Console.WriteLine(new string('-', 10));

            // The 5 top products (by order quantity)
            var third = ___
                .GroupBy(o => o.product_id)
                .Select(grp => new { Product = __.First(p => p.id == grp.Key).nome, Quantities = grp.Sum(grpgrp => grpgrp.quant) })
                .OrderByDescending(q => q.Quantities)
                .Take(5);
            foreach (var item in third)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

            Console.WriteLine(new string('-', 10));

            // The most profitable category
            var category = ___
                .GroupBy(o => o.product_id)
                .Select(g => new { catId = __.First(p => p.id == g.Key).catId, price = __.First(p => p.id == g.Key).unit_price, quantity = g.Sum(p => p.quant) })
                .GroupBy(gg => gg.catId)
                .Select(grp => new { category_name = _.First(c => c.Id == grp.Key).NAME, total_quantity = grp.Sum(g => g.quantity * g.price) })
                .OrderByDescending(g => g.total_quantity)
                .First();
            Console.WriteLine("{0}: {1}", category.category_name, category.total_quantity);
        }