Exemple #1
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper    = new DataMapper();
            var allCategories = dataMapper.GetAllCategories() as Category[] ?? dataMapper.GetAllCategories().ToArray();
            var allProducts   = dataMapper.GetAllProducts() as Product[] ?? dataMapper.GetAllProducts().ToArray();
            var allOrders     = dataMapper.GetAllOrders() as Order[] ?? dataMapper.GetAllOrders().ToArray();

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

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

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

            // Number of products in each Category
            var second = allProducts
                         .GroupBy(p => p.CategoryId)
                         .Select(grp => new { Category = allCategories.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 = allOrders
                        .GroupBy(group => group.ProductId)
                        .Select(orders => new { Product = allProducts.First(p => p.Id == orders.Key).Name, Quantities = orders.Sum(s => s.Quantity) })
                        .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 = allOrders
                           .GroupBy(groupId => groupId.ProductId)
                           .Select(pId => new { allProducts.First(p => p.Id == pId.Key).CategoryId, Price = allProducts.First(p => p.Id == pId.Key).UnitPrice, Quantity = pId.Sum(q => q.Quantity) })
                           .GroupBy(groupCatId => groupCatId.CategoryId)
                           .Select(catId => new { Category = allCategories.First(c => c.Id == catId.Key).Name, TotalQuantity = catId.Sum(g => g.Quantity * g.Price) })
                           .OrderByDescending(g => g.TotalQuantity)
                           .First();

            Console.WriteLine("{0}: {1}", category.Category, category.TotalQuantity);
        }
Exemple #2
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories() as Category[] ?? dataMapper.GetAllCategories().ToArray();
            var allProducts = dataMapper.GetAllProducts() as Product[] ?? dataMapper.GetAllProducts().ToArray();
            var allOrders = dataMapper.GetAllOrders() as Order[] ?? dataMapper.GetAllOrders().ToArray();

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

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

            // Number of products in each Category
            var second = allProducts
                .GroupBy(p => p.CategoryId)
                .Select(grp => new { Category = allCategories.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 = allOrders
                .GroupBy(group => group.ProductId)
                .Select(orders => new { Product = allProducts.First(p => p.Id == orders.Key).Name, Quantities = orders.Sum(s => s.Quantity) })
                .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 = allOrders
                .GroupBy(groupId => groupId.ProductId)
                .Select(pId => new { allProducts.First(p => p.Id == pId.Key).CategoryId, Price = allProducts.First(p => p.Id == pId.Key).UnitPrice, Quantity = pId.Sum(q => q.Quantity) })
                .GroupBy(groupCatId => groupCatId.CategoryId)
                .Select(catId => new { Category = allCategories.First(c => c.Id == catId.Key).Name, TotalQuantity = catId.Sum(g => g.Quantity * g.Price) })
                .OrderByDescending(g => g.TotalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", category.Category, category.TotalQuantity);
        }
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            PrintNamesOfTheFiveMostExpensiveProducts(allProducts);

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

            // Number of products in each category
            PrintNumberOfProductsInEachCategory(allProducts, allCategories);

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

            // The 5 top products (by order quantity)
            PrintFiveTopProducts(allOrders, allProducts);

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

            // The most profitable category
            PrintMostProfitableCategory(allOrders, allProducts, allCategories);
        }
Exemple #4
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

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

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

            // Number of products in each category
            var productsInCategory = allProducts
                .GroupBy(p => p.CategoryId)
                .Select(group => new { Category = allCategories.First(c => c.Id == group.Key).Name, Count = group.Count() })
                .ToList();
            foreach (var item in productsInCategory)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

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

            // The 5 top products (by order quantity)
            var topFiveProducts = allOrders
                .GroupBy(o => o.ProductId)
                .Select(group => new
                {
                        Product = allProducts.First(product => product.Id == group.Key).Name,
                        Quantities = group.Sum(order => order.Quant)
                })
                .OrderByDescending(q => q.Quantities)
                .Take(5);
            foreach (var item in topFiveProducts)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

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

            // The most profitable category
            var profitableCategory = allOrders
                .GroupBy(order => order.ProductId)
                .Select(group => new
                {
                    categoryId = allProducts.First(p => p.Id == group.Key).CategoryId,
                    price = allProducts.First(p => p.Id == group.Key).UnitPrice, quantity = group.Sum(p => p.Quant)
                })
                .GroupBy(group => group.categoryId)
                .Select(group => new { name = allCategories.First(c => c.Id == group.Key).Name, totalQuantity = group.Sum(product => product.quantity * product.price) })
                .OrderByDescending(group => group.totalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", profitableCategory.name, profitableCategory.totalQuantity);
        }
Exemple #5
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

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

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

            // Number of products in each category
            var second = allProducts
                .GroupBy(product => product.CategoryId)
                .Select(products => new { Category = allCategories.First(category => category.Id == products.Key).Name
                    , Count = products.Count() })
                .ToList();

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

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

            // The 5 top products (by order quantity)
            var third = allOrders
                .GroupBy(order => order.ProductId)
                .Select(orders => new { Product = allProducts.First(product => product.Id == orders.Key).Name
                    , Quantities = orders.Sum(order => order.Quant) })
                .OrderByDescending(q => q.Quantities)
                .Take(5);

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

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

            // The most profitable category
            var mostProfitableCategory = allOrders
                .GroupBy(order => order.ProductId)
                .Select(grouping => new { catId = allProducts.First(product => product.Id == grouping.Key).CategoryId
                    , price = allProducts.First(product => product.Id == grouping.Key).UnitPrice
                    , quantity = grouping.Sum(order => order.Quant) })
                .GroupBy(gg => gg.catId)
                .Select(group => new { CategoryName = allCategories.First(category => category.Id == group.Key).Name
                    , TotalQuantity = group.Sum(g => g.quantity * g.price) })
                .OrderByDescending(g => g.TotalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #6
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var mapper        = new DataMapper();
            var allCategories = mapper.GetAllCategories();
            var allProducts   = mapper.GetAllProducts();
            var allOrders     = mapper.GetAllOrders();

            // Names of the 5 most expensive products
            IEnumerable <string> firstFiveMostExpensiveProducts = allProducts
                                                                  .OrderByDescending(p => p.UnitPrice)
                                                                  .Take(5)
                                                                  .Select(p => p.Name);

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

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

            // Number of products in each category
            var productsCountInCategory = allProducts
                                          .GroupBy(p => p.CategoryId)
                                          .Select(grp => new { Category = allCategories.First(c => c.Id == grp.Key).Name, Count = grp.Count() })
                                          .ToList();

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

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

            // The 5 top products (by order quantity)
            var productsOrderedByQuantity = allOrders
                                            .GroupBy(o => o.ProductId)
                                            .Select(grp => new { Product = allProducts.First(p => p.Id == grp.Key).Name, Quantities = grp.Sum(grpgrp => grpgrp.Quant) })
                                            .OrderByDescending(q => q.Quantities)
                                            .Take(5);

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

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

            // The most profitable category
            var mostProfitableCategory = allOrders
                                         .GroupBy(o => o.ProductId)
                                         .Select(g => new { catId = allProducts.First(p => p.Id == g.Key).CategoryId, price = allProducts.First(p => p.Id == g.Key).UnitPrice, quantity = g.Sum(p => p.Quant) })
                                         .GroupBy(gg => gg.catId)
                                         .Select(grp => new { categoryName = allCategories.First(c => c.Id == grp.Key).Name, totalQuantity = grp.Sum(g => g.quantity * g.price) })
                                         .OrderByDescending(g => g.totalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.categoryName, mostProfitableCategory.totalQuantity);
        }
Exemple #7
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dataMapper = new DataMapper();
            var categories = dataMapper.GetAllCategories().ToArray();
            var products   = dataMapper.GetAllProducts().ToArray();
            var orders     = dataMapper.GetAllOrders().ToArray();

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

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

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

            // Number of products in each Category
            var productsCountInCategory = products
                                          .GroupBy(p => p.CatId)
                                          .Select(grp => new { Category = categories.First(c => c.Id == grp.Key).Name, Count = grp.Count() })
                                          .ToList();

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

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

            // The 5 top products (by Order quantity)
            var mostQuantityProducts = orders
                                       .GroupBy(o => o.ProductId)
                                       .Select(grp => new { Product = products.First(p => p.Id == grp.Key).Name, Quantities = grp.Sum(grpgrp => grpgrp.Quant) })
                                       .OrderByDescending(q => q.Quantities)
                                       .Take(5);

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

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

            // The most profitable Category
            var category = orders
                           .GroupBy(o => o.ProductId)
                           .Select(g => new { catId = products.First(p => p.Id == g.Key).CatId, price = products.First(p => p.Id == g.Key).UnitPrice, quantity = g.Sum(p => p.Quant) })
                           .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}", category.category_name, category.total_quantity);
        }
Exemple #8
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var filePaths     = new DataMapper();
            var allCategories = filePaths.GetAllCategories();
            var allProducts   = filePaths.GetAllProducts();
            var allOrders     = filePaths.GetAllOrders();

            // Names of the 5 most expensive products
            var first = allProducts
                        .OrderByDescending(product => product.UnitPrice)
                        .Take(5)
                        .Select(product => product.Name);

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

            // Number of products in each Category
            var second = allProducts
                         .GroupBy(product => product.CatID)
                         .Select(group => new { Category = allCategories.First(c => c.ID == group.Key).Name, Count = group.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 = allOrders
                        .GroupBy(o => o.ProductID)
                        .Select(group => new { Product = allProducts.First(p => p.ID == group.Key).Name, Quantities = group.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 = allOrders
                           .GroupBy(order => order.ProductID)
                           .Select(group => new { catId = allProducts.First(p => p.ID == group.Key).CatID, price = allProducts.First(p => p.ID == group.Key).UnitPrice, quantity = group.Sum(p => p.Quant) })
                           .GroupBy(categ => categ.catId)
                           .Select(goup => new { category_name = allCategories.First(c => c.ID == goup.Key).Name, total_quantity = goup.Sum(g => g.quantity * g.price) })
                           .OrderByDescending(group => group.total_quantity)
                           .First();

            Console.WriteLine("{0}: {1}", category.category_name, category.total_quantity);
        }
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            IEnumerable<Product> products = allProducts as Product[] ?? allProducts.ToArray();
            var top5MostExpensiveProducts = products
                .OrderByDescending(p => p.UnitPrice)
                .Take(5)
                .Select(p => p.Name);
            Console.WriteLine(string.Join(Environment.NewLine, top5MostExpensiveProducts));

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

            // Number of products in each Category
            var NumsOfProducts = products
                .GroupBy(p => p.CategoryId)
                .Select(grp => new { Category = allCategories.First(category => category.Id == grp.Key).Name, Count = grp.Count() })
                .ToList();
            foreach (var item in NumsOfProducts)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

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

            // The 5 top products (by Order quantity)
            var orders = allOrders as Order[] ?? allOrders.ToArray();
            var top5Products = orders
                .GroupBy(order => order.ProductId)
                .Select(grouping => new { Product = products.First(product => product.Id == grouping.Key).Name, Quantities = grouping.Sum(order => order.Quantity) })
                .OrderByDescending(arg => arg.Quantities)
                .Take(5);
            foreach (var item in top5Products)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

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

            // The most profitable Category
            var mostProfitableCategory = orders
                .GroupBy(order => order.ProductId)
                .Select(grouping => new {products.First(product => product.Id == grouping.Key).CategoryId, price = products.First(product => product.Id == grouping.Key).UnitPrice, quantity = grouping.Sum(order => order.Quantity) })
                .GroupBy(group => group.CategoryId)
                .Select(grouping => new { category_name = allCategories.First(category => category.Id == grouping.Key).Name, total_quantity = grouping.Sum(arg => arg.quantity * arg.price) })
                .OrderByDescending(arg => arg.total_quantity)
                .First();
            Console.WriteLine("{0}: {1}", mostProfitableCategory.category_name, mostProfitableCategory.total_quantity);
        }
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            DataMapper dataMapper = new DataMapper();

            IEnumerable<Category> allCategories = dataMapper.GetAllCategories();
            IEnumerable<Product> allProducts = dataMapper.GetAllProducts();
            IEnumerable<Order> allOrders = dataMapper.GetAllOrders();

            IEnumerable<string> FiveMostExpensiveProducts = NewMethod(allProducts);

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

            DrawSeparationLine();

            var numberOfProductsByCategory = allProducts
                .GroupBy(p => p.CategoryId)
                .Select(grp => new { Category = allCategories.First(c => c.Id == grp.Key).Name, Count = grp.Count() })
                .ToList();

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

            DrawSeparationLine();

            var fiveTopProductsbyQuantity = allOrders
                 .GroupBy(o => o.ProductId)
                 .Select(grp => new { Product = allProducts.First(p => p.Id == grp.Key).Nome, Quantities = grp.Sum(grpgrp => grpgrp.Quant) })
                 .OrderByDescending(q => q.Quantities)
                 .Take(5);

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

            DrawSeparationLine();

            // The most profitable category
            var category = allOrders
                .GroupBy(o => o.ProductId)
                .Select(g => new { catId = allProducts.First(p => p.Id == g.Key).CategoryId, price = allProducts.First(p => p.Id == g.Key).Price, quantity = g.Sum(p => p.Quant) })
                .GroupBy(gg => gg.catId)
                .Select(grp => new { category_name = allCategories.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);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            DataMapper allData = new DataMapper();
            var categories = allData.GetAllCategories();
            var products = allData.GetAllProducts();
            var orders = allData.GetAllOrders();

            // Names of the 5 most expensive products
             IEnumerable<string> mostExpensiveProducts = products
                .OrderByDescending(p => p.UnitPrice)
                .Take(5)
                .Select(p => p.ProductName);
            Console.WriteLine(string.Join(Environment.NewLine, mostExpensiveProducts));

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

            // Number of products in each category
            var productsByCategories = products
                .GroupBy(p => p.CategoryID)
                .Select(group => new { Category = categories.First(c => c.CategoryID == group.Key).CategoryName, Count = group.Count() })
                .ToList();
            foreach (var product in productsByCategories)
            {
                Console.WriteLine("{0}: {1}", product.Category, product.Count);
            }

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

            // The 5 top products (by order quantity)
            var productsByQuantity = orders
                .GroupBy(order => order.ProductID)
                .Select(group => new { Product = products.First(p => p.ProductID == group.Key).ProductName, Quantities = group.Sum(order => order.Quantity) })
                .OrderByDescending(q => q.Quantities)
                .Take(5);
            foreach (var product in productsByQuantity)
            {
                Console.WriteLine("{0}: {1}", product.Product, product.Quantities);
            }

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

            // The most profitable category
            var profitableCategory = orders
                .GroupBy(order => order.ProductID)
                .Select(group => new { CategoryID = products.First(p => p.ProductID == group.Key).CategoryID, price = products.First(p => p.ProductID == group.Key).UnitPrice, quantity = group.Sum(p => p.Quantity) })
                .GroupBy(category => category.CategoryID)
                .Select(group => new { categoryName = categories.First(c => c.CategoryID == group.Key).CategoryName, totalQuantity = group.Sum(g => g.quantity * g.price) })
                .OrderByDescending(g => g.totalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", profitableCategory.categoryName, profitableCategory.totalQuantity);
        }
Exemple #12
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var filePaths = new DataMapper();
            var allCategories = filePaths.GetAllCategories();
            var allProducts = filePaths.GetAllProducts();
            var allOrders = filePaths.GetAllOrders();

            // Names of the 5 most expensive products
            var first = allProducts
                        .OrderByDescending(product => product.UnitPrice)
                        .Take(5)
                        .Select(product => product.Name);

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

            // Number of products in each Category
            var second = allProducts
                        .GroupBy(product => product.CatID)
                        .Select(group => new { Category = allCategories.First(c => c.ID == group.Key).Name, Count = group.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 = allOrders
                        .GroupBy(o => o.ProductID)
                        .Select(group => new { Product = allProducts.First(p => p.ID == group.Key).Name, Quantities = group.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 = allOrders
                            .GroupBy(order => order.ProductID)
                            .Select(group => new { catId = allProducts.First(p => p.ID == group.Key).CatID, price = allProducts.First(p => p.ID == group.Key).UnitPrice, quantity = group.Sum(p => p.Quant) })
                            .GroupBy(categ => categ.catId)
                            .Select(goup => new { category_name = allCategories.First(c => c.ID == goup.Key).Name, total_quantity = goup.Sum(g => g.quantity * g.price) })
                            .OrderByDescending(group => group.total_quantity)
                            .First();
            Console.WriteLine("{0}: {1}", category.category_name, category.total_quantity);
        }
Exemple #13
0
        internal static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            var mostExpensive5Products = dataMapper.Get5MostExpensiveProducts();

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

            // Number of products in each Category
            var numberOfProductsForEachCategory = allProducts
                .GroupBy(p => p.CatalogueId)
                .Select(grp => new { Category = allCategories.First(c => c.Id == grp.Key).Name, Count = grp.Count() })
                .ToList();

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

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

            // The 5 top products (by Order quantity)
            var top5Products = allOrders
                .GroupBy(o => o.ProductId)
                .Select(grp => new { Product = allProducts.First(p => p.Id == grp.Key).Name, Quantities = grp.Sum(grpgrp => grpgrp.Quantity) })
                .OrderByDescending(q => q.Quantities)
                .Take(5);

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

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

            // The most profitable Category
            var mostProfitableCategory = allOrders
                .GroupBy(o => o.ProductId)
                .Select(g => new { catId = allProducts.First(p => p.Id == g.Key).CatalogueId, price = allProducts.First(p => p.Id == g.Key).UnitPrice, quantity = g.Sum(p => p.Quantity) })
                .GroupBy(gg => gg.catId)
                .Select(grp => new { categoryName = allCategories.First(c => c.Id == grp.Key).Name, totalQuantity = grp.Sum(g => g.quantity * g.price) })
                .OrderByDescending(g => g.totalQuantity)
                .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.categoryName, mostProfitableCategory.totalQuantity);
        }
Exemple #14
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            IDataMapper dataMapper = new DataMapper();

            IEnumerable<ICategory> categories = dataMapper.GetAllCategories();
            IEnumerable<IProduct> products = dataMapper.GetAllProducts();
            IEnumerable<IOrder> orders = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            IEnumerable<string> fiveMostExpensiveProducts = GetNamesOfMostExpensiveProducts(products, 5);

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

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

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

            // The 5 top products (by order quantity)
            var fiveTopOrders = orders
                .GroupBy(o => o.ProductId)
                .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 fiveTopOrders)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

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

            // The most profitable category
            var mostProfitableCategory = orders
                .GroupBy(o => o.ProductId)
                .Select(g => new { catId = products.First(p => p.Id == g.Key).CategoryId, 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}", mostProfitableCategory.category_name, mostProfitableCategory.total_quantity);
        }
Exemple #15
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

            var fiveMostExpensiveProducts = allProducts
                                            .OrderByDescending(product => product.UnitPrice)
                                            .Take(5)
                                            .Select(product => product.Name);

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

            var numberOfProductsInEachCategory = allProducts
                                                .GroupBy(product => product.CategoryID)
                                                .Select(properties => new { Category = allCategories.First(category => category.ID == properties.Key).Name, Count = properties.Count() })
                                                .ToList();

            foreach (var NumberOfProductsInCategory in numberOfProductsInEachCategory)
            {
                Console.WriteLine("{0}: {1}", NumberOfProductsInCategory.Category, NumberOfProductsInCategory.Count);
            }
            Console.WriteLine(new string('-', 10));

            var fiveTopProductsByOrderQuantity = allOrders
                                                .GroupBy(order => order.ProductID)
                                                .Select(properties => new { Product = allProducts.First(product => product.ID == properties.Key).Name, Quantities = properties.Sum(order => order.Quantity) })
                                                .OrderByDescending(products => products.Quantities)
                                                .Take(5);

            foreach (var item in fiveTopProductsByOrderQuantity)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }
            Console.WriteLine(new string('-', 10));

            var mostProfitableCategory = allOrders
                .GroupBy(order => order.ProductID)
                .Select(grouping => new { CategoryId = allProducts.First(product => product.ID == grouping.Key).CategoryID, Price = allProducts.First(product => product.ID == grouping.Key).UnitPrice, Quantity = grouping.Sum(order => order.Quantity) })
                .GroupBy(categories => categories.CategoryId)
                .Select(grouping => new { CategoryName = allCategories.First(category => category.ID == grouping.Key).Name, TotalQuantity = grouping.Sum(categories => categories.Quantity * categories.Price) })
                .OrderByDescending(g => g.TotalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #16
0
 static void Main()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     DataMapper dataMapper = new DataMapper();
     IEnumerable<Category> allCategories = dataMapper.GetAllCategories();
     List<Category> allCategoriesList = allCategories.ToList();
     IEnumerable<Product> allProducts = dataMapper.GetAllProducts();
     List<Product> allProductsList = allProducts.ToList();
     IEnumerable<Order> allOrders = dataMapper.GetAllOrders();
     List<Order> allOrdersList = allOrders.ToList();
     PrintMostExpensiveProducts(allProductsList);
     PrintNumberOfProductsInCategories(allProductsList, allCategoriesList);
     PrintTopProductsByOrderQuantity(allOrdersList, allProductsList);
     PrintMostProfitableCategory(allOrdersList, allProductsList, allCategoriesList);
 }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var mapper     = new DataMapper();
            var categories = mapper.GetAllCategories();
            var products   = mapper.GetAllProducts();
            var orders     = mapper.GetAllOrders();

            GetTheMostExpensiveProducts(products, 5);


            PrintNumberOfProductsPerCategory(products, categories);

            PrintTheMostOrderedProducts(orders, products, 5);

            PrintTheMostProfitableCategory(orders, products, categories);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var mapper     = new DataMapper();
            var categories = mapper.GetAllCategories();
            var products   = mapper.GetAllProducts();
            var orders     = mapper.GetAllOrders();

            DisplayTopFiveProductsByPrice(products);

            DisplayCategoriesAndNumberOfProducts(products, categories);

            DisplayTopFiveProductsByQuantity(orders, products);

            DisplayTheMostProfitableCategory(orders, products, categories);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var mapper     = new DataMapper();
            var categories = mapper.GetAllCategories();
            var products   = mapper.GetAllProducts();
            var orders     = mapper.GetAllOrders();

            // Names of the 5 most expensive products
            GetTheMostExpensiveProducts(products, 5);

            // Number of products in each category
            PrintNumberOfProductsPerCategory(products, categories);

            // The 5 top products (by order quantity)
            PrintTheMostOrderedProducts(orders, products, 5);

            // The most profitable category
            PrintTheMostProfitableCategory(orders, products, categories);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var mapper = new DataMapper();
            var categories = mapper.GetAllCategories();
            var products = mapper.GetAllProducts();
            var orders = mapper.GetAllOrders();

            // Names of the 5 most expensive products
            GetTheMostExpensiveProducts(products, 5);

            // Number of products in each category
            PrintNumberOfProductsPerCategory(products, categories);

            // The 5 top products (by order quantity)
            PrintTheMostOrderedProducts(orders, products, 5);

            // The most profitable category
            PrintTheMostProfitableCategory(orders, products, categories);
        }
Exemple #21
0
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper    = new DataMapper();
            var consoleWriter = new ConsoleWriter();
            var categories    = dataMapper.GetAllCategories();
            var products      = dataMapper.GetAllProducts();
            var orders        = dataMapper.getAllOrders();

            // Names of the 5 most expensive products
            consoleWriter.Write(MostExpensiveProducts(products, 5));

            // Number of products in each category
            consoleWriter.Write(NumberOfProductsInCategory(products, categories));

            // The 5 top products (by order quantity)
            consoleWriter.Write(TopProducts(products, orders, 5));

            // The most profitable category
            consoleWriter.Write(MostProfitableCategory(products, orders, categories));
        }
Exemple #22
0
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var data = new DataMapper();
            var allCategories = data.GetAllCategories();
            var allProducts = data.GetAllProducts();
            var allOrders = data.GetAllOrders();

            PrintNamesOfTheFiveMostExpensiveProducts(allProducts);

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

            PrintNumberOfProductsInEachCategory(allProducts, allCategories);

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

            PrintFiveTopProducts(allOrders, allProducts);

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

            PrintMostProfitableCategory(allOrders, allProducts, allCategories);
        }
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dataMapper          = new DataMapper();
            var allCategoriesInData = dataMapper.GetAllCategories();
            var allProductsInData   = dataMapper.GetAllProducts();
            var allOrdersInData     = dataMapper.GetAllOrders();

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

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

            PrintLine();

            var numberOfProdcutsPerCategory = allProductsInData
                                              .GroupBy(p => p.CategoryId)
                                              .Select(group => new
            {
                Category = allCategoriesInData
                           .First(c => c.Id == group.Key)
                           .Name,
                Count = group.Count()
            })
                                              .ToList();

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

            PrintLine();

            var productsWithTheMostQuantity = allOrdersInData
                                              .GroupBy(order => order.ProductId)
                                              .Select(group => new
            {
                Product = allProductsInData
                          .First(p => p.Id == group.Key)
                          .Name,
                Quantities = group.Sum(grpgrp => grpgrp.Quantity)
            })
                                              .OrderByDescending(products => products.Quantities)
                                              .Take(5);

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

            PrintLine();

            var mostProfitableCategory = allOrdersInData
                                         .GroupBy(o => o.ProductId)
                                         .Select(group => new
            {
                CatId = allProductsInData
                        .First(product => product.Id == group.Key)
                        .CategoryId,
                Price = allProductsInData
                        .First(product => product.Id == group.Key)
                        .UnitPrice,
                Quantity = group.Sum(order => order.Quantity)
            })
                                         .GroupBy(group => group.CatId)
                                         .Select(group => new
            {
                CategoryName = allCategoriesInData
                               .First(category => category.Id == group.Key)
                               .Name,
                TotalQuantity = group.Sum(g => g.Quantity * g.Price)
            })
                                         .OrderByDescending(group => group.TotalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #24
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper    = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts   = dataMapper.GetAllProducts();
            var allOrders     = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            var first = allProducts
                        .OrderByDescending(product => product.UnitPrice)
                        .Take(5)
                        .Select(product => product.Name);

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

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

            // Number of products in each category
            var second = allProducts
                         .GroupBy(product => product.CategoryId)
                         .Select(products => new { Category = allCategories.First(category => category.Id == products.Key).Name
                                                   , Count  = products.Count() })
                         .ToList();

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

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

            // The 5 top products (by order quantity)
            var third = allOrders
                        .GroupBy(order => order.ProductId)
                        .Select(orders => new { Product      = allProducts.First(product => product.Id == orders.Key).Name
                                                , Quantities = orders.Sum(order => order.Quant) })
                        .OrderByDescending(q => q.Quantities)
                        .Take(5);

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

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

            // The most profitable category
            var mostProfitableCategory = allOrders
                                         .GroupBy(order => order.ProductId)
                                         .Select(grouping => new { catId      = allProducts.First(product => product.Id == grouping.Key).CategoryId
                                                                   , price    = allProducts.First(product => product.Id == grouping.Key).UnitPrice
                                                                   , quantity = grouping.Sum(order => order.Quant) })
                                         .GroupBy(gg => gg.catId)
                                         .Select(group => new { CategoryName    = allCategories.First(category => category.Id == group.Key).Name
                                                                , TotalQuantity = group.Sum(g => g.quantity * g.price) })
                                         .OrderByDescending(g => g.TotalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #25
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();


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

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


            // Number of products in each category
            var productsInCategory = products
                                     .GroupBy(product => product.CategoryId)
                                     .Select(group =>
                                             new { CategoryName = categories.First(category => category.Id == group.Key).Name,
                                                   ProductCount = group.Count() })
                                     .ToList();

            foreach (var item in productsInCategory)
            {
                Console.WriteLine("{0}: {1}", item.CategoryName, item.ProductCount);
            }
            Console.WriteLine(new string('-', 10));


            // The 5 top products (by order quantity)
            var topFiveProducts = orders
                                  .GroupBy(order => order.ProductId)
                                  .Select(group =>
                                          new { ProductName = products.First(product => product.Id == group.Key).Name,
                                                Quantities  = group.Sum(order => order.Quantity) })
                                  .OrderByDescending(q => q.Quantities)
                                  .Take(5);

            foreach (var item in topFiveProducts)
            {
                Console.WriteLine("{0}: {1}", item.ProductName, item.Quantities);
            }
            Console.WriteLine(new string('-', 10));



            // Finds the most profitable category
            var mostProfitableCategory = orders
                                         .GroupBy(order => order.ProductId)
                                         .Select(group =>
                                                 new { Category = products.First(product => product.Id == group.Key).CategoryId,
                                                       Price    = products.First(product => product.Id == group.Key).UnitPrice,
                                                       Quantity = group.Sum(order => order.Quantity) })
                                         .GroupBy(product => product.Category)
                                         .Select(group =>
                                                 new { CategoryName  = categories.First(category => category.Id == group.Key).Name,
                                                       TotalQuantity = group.Sum(g => g.Quantity * g.Price) })
                                         .OrderByDescending(group => group.TotalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var categories = dataMapper.GetAllCategories();
            var products = dataMapper.GetAllProducts();
            var orders = dataMapper.GetAllOrders();

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

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

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

            // Number of products in each category
            var second = products
                .GroupBy(product => product.CategoryId)
                .Select(group => new
                {
                    Category = categories.First(c => c.Id == group.Key).Name,
                    Count = group.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 topProductsByOrderQuantity = orders
                .GroupBy(order => order.ProductId)
                .Select(group => new
                {
                    Product = products.First(p => p.Id == group.Key).Name,
                    Quantities = group.Sum(grpgrp => grpgrp.Quantity)
                })
                .OrderByDescending(q => q.Quantities)
                .Take(5);

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

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

            // The most profitable category
            var mostProfitableCategory = orders
                .GroupBy(o => o.ProductId)
                .Select(g => new
                {
                    CategoryId = products.First(p => p.Id == g.Key).CategoryId,
                    Price = products.First(p => p.Id == g.Key).UnitPrice,
                    Quantity = g.Sum(p => p.Quantity)
                })
                .GroupBy(gg => gg.CategoryId)
                .Select(grp => new
                {
                    CategoryName = categories.First(c => c.Id == grp.Key).Name,
                    TotalQuantity = grp.Sum(g => g.Quantity * g.Price)
                })
                .OrderByDescending(g => g.TotalQuantity)
                .First();
            Console.WriteLine("{0}: {1}",
                mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #27
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper       = new DataMapper();
            var getAllCategories = dataMapper.GetAllCategories();
            var getAllProducts   = dataMapper.GetAllProducts();
            var getAllOrders     = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            var allProducts = getAllProducts as Product[] ?? getAllProducts.ToArray();
            var fiveMostExpensiceProducts = allProducts
                                            .OrderByDescending(p => p.UnitPrice)
                                            .Select(p => p.Name)
                                            .Take(5);

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

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

            // Number of products in each category
            var numberOfProductsInEachCategory = allProducts
                                                 .GroupBy(p => p.CategoryId)
                                                 .Select(groupByCategoryId => new
            {
                Name  = getAllCategories.First(c => c.Id == groupByCategoryId.Key).Name,
                Count = groupByCategoryId.Count()
            })
                                                 .ToList();

            foreach (var category in numberOfProductsInEachCategory)
            {
                Console.WriteLine("{0}: {1}", category.Name, category.Count);
            }

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

            // The 5 top products (by order quantity)
            var allOrders = getAllOrders as Order[] ?? getAllOrders.ToArray();

            var topFiveProducts = allOrders
                                  .GroupBy(o => o.ProductId)
                                  .Select(groupByProductId => new
            {
                Name     = allProducts.First(p => p.Id == groupByProductId.Key).Name,
                Quantity = groupByProductId.Sum(p => p.Quantity)
            })
                                  .OrderByDescending(p => p.Quantity)
                                  .Take(5);

            foreach (var product in topFiveProducts)
            {
                Console.WriteLine("{0}: {1}", product.Name, product.Quantity);
            }

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

            // The most profitable category
            var mostProfitableCategory = allOrders
                                         .GroupBy(o => o.ProductId)
                                         .Select(groupByProductId => new
            {
                CategoryId      = allProducts.First(p => p.Id == groupByProductId.Key).CategoryId,
                ProductPrice    = allProducts.First(p => p.Id == groupByProductId.Key).UnitPrice,
                ProductQuantity = groupByProductId.Sum(p => p.Quantity)
            })
                                         .GroupBy(p => p.CategoryId)
                                         .Select(groupByCategoryId => new
            {
                CategoryName  = getAllCategories.First(c => c.Id == groupByCategoryId.Key).Name,
                TotalQuantity = groupByCategoryId.Sum(c => c.ProductQuantity * c.ProductPrice)
            })
                                         .OrderByDescending(c => c.TotalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
Exemple #28
0
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dataMapper    = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts   = dataMapper.GetAllProducts();
            var allOrders     = dataMapper.GetAllOrders();

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

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

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

            // Number of products in each category
            var amountOfProductsPerCategory = allProducts
                                              .GroupBy(p => p.CategoryId)
                                              .Select(group => new
            {
                Category = allCategories
                           .First(c => c.Id == group.Key).Name,
                Count = group.Count()
            })
                                              .ToList();

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

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


            // The 5 top products (by order Quantity)
            var topProducts = allOrders
                              .GroupBy(o => o.ProductId)
                              .Select(group => new
            {
                Product = allProducts
                          .First(p => p.Id == group.Key).Name,
                Quantities = group.Sum(g => g.Quantity)
            })
                              .OrderByDescending(q => q.Quantities)
                              .Take(5);

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

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

            // The most profitable category
            var mostProfitableCategory = allOrders
                                         .GroupBy(o => o.ProductId)
                                         .Select(g => new
            {
                allProducts
                .First(p => p.Id == g.Key).CategoryId,
                Price = allProducts
                        .First(p => p.Id == g.Key).UnitPrice,
                Quantity = g.Sum(p => p.Quantity)
            })
                                         .GroupBy(g => g.CategoryId)
                                         .Select(group => new
            {
                CategoryName = allCategories
                               .First(c => c.Id == group.Key).Name,
                ToatalQuantity = group.Sum(g => g.Quantity * g.Price)
            })
                                         .OrderByDescending(g => g.ToatalQuantity)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.ToatalQuantity);
        }
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var dataMapper = new DataMapper();
            var allCategories = dataMapper.GetAllCategories();
            var allProducts = dataMapper.GetAllProducts();
            var allOrders = dataMapper.GetAllOrders();

            var fiveMostExpensiveProductsNames =
                allProducts.OrderByDescending(p => p.UnitPrice).Take(5).Select(p => p.Name);

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

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

            var numberOfProductsInCategory =
                allProducts.GroupBy(p => p.CategoryId)
                    .Select(
                        group =>
                        new
                            {
                                Category = allCategories.First(c => c.Id == group.Key).Name,
                                Count = group.Count()
                            })
                    .ToList();
            foreach (var item in numberOfProductsInCategory)
            {
                Console.WriteLine("{0}: {1}", item.Category, item.Count);
            }

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

            var topFiveProductsOrderedByQuantity =
                allOrders.GroupBy(order => order.ProductId)
                    .Select(
                        group =>
                        new
                            {
                                Product = allProducts.FirstOrDefault(p => p.Id == group.Key).Name,
                                Quantities = group.Sum(order => order.Quantity)
                            })
                    .OrderByDescending(q => q.Quantities)
                    .Take(5);
            foreach (var item in topFiveProductsOrderedByQuantity)
            {
                Console.WriteLine("{0}: {1}", item.Product, item.Quantities);
            }

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

            var mostProfitableCategory =
                allOrders.GroupBy(o => o.ProductId)
                    .Select(
                        grouping =>
                        new
                            {
                                ProductCategoryId = allProducts.First(p => p.Id == grouping.Key).CategoryId,
                                Price = allProducts.First(p => p.Id == grouping.Key).UnitPrice,
                                Quantity = grouping.Sum(p => p.Quantity)
                            })
                    .GroupBy(product => product.ProductCategoryId)
                    .Select(
                        productGroup =>
                        new
                            {
                                CategoryName = allCategories.First(c => c.Id == productGroup.Key).Name,
                                TotalQuantity = productGroup.Sum(g => g.Quantity * g.Price)
                            })
                    .OrderByDescending(productGroup => productGroup.TotalQuantity)
                    .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            DataMapper             dataMapper = new DataMapper();
            IEnumerable <Category> categories = dataMapper.GetAllCategories();
            IEnumerable <Product>  products   = dataMapper.GetAllProducts();
            IEnumerable <Order>    orders     = dataMapper.GetAllOrders();

            // Names of the 5 most expensive products
            IEnumerable <string> expesiveProducts = products
                                                    .OrderByDescending(product => product.UnitPrice)
                                                    .Take(5)
                                                    .Select(product => product.Name);

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

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

            // Number of products in each Category
            var inEachCategory = products
                                 .GroupBy(product => product.CategoryId)
                                 .Select(grp => new
            {
                Category = categories.First(c => c.Id == grp.Key).Name,
                Count    = grp.Count()
            })
                                 .ToList();

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

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

            // The 5 top products (by Order quantity)
            var topProducts = orders
                              .GroupBy(order => order.ProductId)
                              .Select(grp => new
            {
                Product    = products.First(product => product.Id == grp.Key).Name,
                Quantities = grp.Sum(groupOrder => groupOrder.Quant)
            })
                              .OrderByDescending(quantity => quantity.Quantities)
                              .Take(5);

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

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

            // The most profitable Category
            var category = orders
                           .GroupBy(order => order.ProductId)
                           .Select(group => new
            {
                categoryId = products.First(product => product.Id == group.Key).CategoryId,
                price      = products.First(product => product.Id == group.Key).UnitPrice,
                quantity   = group.Sum(product => product.Quant)
            })
                           .GroupBy(categoryGroup => categoryGroup.categoryId)
                           .Select(grp => new
            {
                categoryName  = categories.First(cat => cat.Id == grp.Key).Name,
                totalQuantity = grp.Sum(group => group.quantity * group.price)
            })
                           .OrderByDescending(group => group.totalQuantity)
                           .First();

            Console.WriteLine("{0}: {1}", category.categoryName, category.totalQuantity);
        }
Exemple #31
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var mapper = new DataMapper();

            var categories = mapper.GetAllCategories();
            var products   = mapper.GetAllProducts();
            var orders     = mapper.GetAllOrders();


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

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


            // Number of products in each category
            var productsByCategories = products
                                       .GroupBy(p => p.CategoryId)
                                       .Select(grp => new
            {
                Category = categories
                           .First(c => c.Id == grp.Key).Name,
                Count = grp.Count()
            })
                                       .ToList();

            foreach (var productsGroup in productsByCategories)
            {
                Console.WriteLine("{0}: {1}", productsGroup.Category, productsGroup.Count);
            }
            Console.WriteLine(new string('-', 10));


            // The 5 top products (by order Quantity)
            var mostOrderedProducts = orders
                                      .GroupBy(o => o.ProductId)
                                      .Select(g => new
            {
                Product = products
                          .First(p => p.Id == g.Key).Name,
                Quantities = g.Sum(o => o.Quantity)
            })
                                      .OrderByDescending(q => q.Quantities)
                                      .Take(5);

            foreach (var order in mostOrderedProducts)
            {
                Console.WriteLine("{0}: {1}", order.Product, order.Quantities);
            }
            Console.WriteLine(new string('-', 10));


            // The most profitable category
            var mostProfitableCategory = orders
                                         .GroupBy(o => o.ProductId)
                                         .Select(g => new
            {
                CategoryId = products
                             .First(p => p.Id == g.Key).CategoryId,
                Price = products
                        .First(p => p.Id == g.Key).UnitPrice,
                Quantity = g.Sum(p => p.Quantity)
            })
                                         .GroupBy(g => g.CategoryId)
                                         .Select(g => new
            {
                CategoryName = categories
                               .First(c => c.Id == g.Key).Name,
                TotalSum = g.Sum(o => o.Quantity * o.Price)
            })
                                         .OrderByDescending(g => g.TotalSum)
                                         .First();

            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalSum);
        }
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var dataMapper = new DataMapper();
            var allCategoriesInData = dataMapper.GetAllCategories();
            var allProductsInData = dataMapper.GetAllProducts();
            var allOrdersInData = dataMapper.GetAllOrders();

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

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

            PrintLine();

            var numberOfProdcutsPerCategory = allProductsInData
                .GroupBy(p => p.CategoryId)
                .Select(group => new
                {
                    Category = allCategoriesInData
                        .First(c => c.Id == group.Key)
                        .Name,
                    Count = group.Count()                 
                })
                .ToList();

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

            PrintLine();

            var productsWithTheMostQuantity = allOrdersInData
                .GroupBy(order => order.ProductId)
                .Select(group => new
                {
                    Product = allProductsInData
                        .First(p => p.Id == group.Key)
                        .Name,
                    Quantities = group.Sum(grpgrp => grpgrp.Quantity)
                })
                .OrderByDescending(products => products.Quantities)
                .Take(5);

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

            PrintLine();

            var mostProfitableCategory = allOrdersInData
                .GroupBy(o => o.ProductId)
                .Select(group => new 
                {
                    CatId = allProductsInData
                        .First(product => product.Id == group.Key)
                        .CategoryId,
                    Price = allProductsInData
                        .First(product => product.Id == group.Key)
                        .UnitPrice,
                    Quantity = group.Sum(order => order.Quantity)                
                })
                .GroupBy(group => group.CatId)
                .Select(group => new
                {
                    CategoryName = allCategoriesInData
                        .First(category => category.Id == group.Key)
                        .Name,
                    TotalQuantity = group.Sum(g => g.Quantity * g.Price)                 
                })
                .OrderByDescending(group => group.TotalQuantity)
                .First();
            Console.WriteLine("{0}: {1}", mostProfitableCategory.CategoryName, mostProfitableCategory.TotalQuantity);
        }