Пример #1
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var allCustomers       = DataLoader.LoadCustomers();
            var filiteredCustomers = allCustomers.Where(c => c.Region == "WA");

            PrintCustomerInformation(filiteredCustomers);
        }
Пример #2
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var allCustomers = DataLoader.LoadCustomers();
            var lessThan500  = allCustomers.Where(c => c.Orders.Any(o => o.Total < 500));

            PrintCustomerInformation(lessThan500);
        }
Пример #3
0
        /// <summary>
        /// Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        /// </summary>
        static void Exercise21()
        {
            var allCustomers = DataLoader.LoadCustomers();

            var allOrders = allCustomers.SelectMany(p => p.Orders);

            string decider = "";

            foreach (Customer c in allCustomers)
            {
                Console.WriteLine(c.CompanyName);
                foreach (Order o in allOrders)
                {
                    if (c.Orders.Contains(o))
                    {
                        if (o.OrderDate.Year.ToString() != decider)
                        {
                            Console.WriteLine(o.OrderDate.Year);
                            decider = o.OrderDate.Year.ToString();
                        }
                        Console.WriteLine("    " + o.OrderDate.Month + " - " + o.Total);
                    }
                }
                decider = "";
            }
        }
Пример #4
0
        /// <summary>
        /// ***Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        /// </summary>
        static void Exercise21()
        {
            var Customers = DataLoader.LoadCustomers();

            foreach (var customer in Customers)
            {
                var innerYear = 0;
                Console.WriteLine(customer.CompanyName);
                foreach (var order in customer.Orders)
                {
                    var year = order.OrderDate.Year;

                    if (innerYear == year)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine(year);
                        foreach (var orders in customer.Orders)
                        {
                            if (orders.OrderDate.Year == year)
                            {
                                Console.WriteLine("     {0} -  $ {1}", orders.OrderDate.Month, orders.Total);
                                innerYear = year;
                            }
                        }
                    }
                }
                Console.WriteLine("");
            }
        }
Пример #5
0
        /// <summary>
        /// Print the Company Name and most recent order for each customer in Washington
        /// </summary>
        static void Exercise13()
        {
            var Customers = DataLoader.LoadCustomers();

            var NameWA = (from customers in Customers
                          where customers.Region == "WA"
                          select customers).ToList();

            foreach (var customer in NameWA)
            {
                Console.WriteLine(customer.CompanyName);
                var orderTimes = DateTime.Today;

                foreach (var order in customer.Orders)
                {
                    if (orderTimes == DateTime.Today)
                    {
                        orderTimes = order.OrderDate;
                    }
                    else if (orderTimes < order.OrderDate)
                    {
                        orderTimes = order.OrderDate;
                    }
                }
                Console.WriteLine(orderTimes);
                Console.WriteLine("");
            }
        }
Пример #6
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var customersAndOrdersWA = DataLoader.LoadCustomers()
                                       .Where(i => i.Region == "WA");

            PrintCustomerInformation(customersAndOrdersWA);
        }
Пример #7
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var customers = DataLoader.LoadCustomers();

            foreach (var customer in customers)
            {
                decimal sumOrderTotal = 0;
                foreach (var order in customer.Orders)
                {
                    decimal orderAdd = sumOrderTotal + order.Total;
                    sumOrderTotal = orderAdd;
                }
                if (sumOrderTotal < 500)
                {
                    Console.WriteLine("==============================================================================");
                    Console.WriteLine(customer.CompanyName);
                    Console.WriteLine(customer.Address);
                    Console.WriteLine("{0}, {1} {2} {3}", customer.City, customer.Region, customer.PostalCode, customer.Country);
                    Console.WriteLine("p:{0} f:{1}", customer.Phone, customer.Fax);
                    Console.WriteLine();
                    Console.WriteLine("\tOrders");
                    foreach (var order in customer.Orders)
                    {
                        Console.WriteLine("\t{0} {1:MM-dd-yyyy} {2,10:c}", order.OrderID, order.OrderDate, order.Total);
                    }
                    Console.WriteLine("Total orders:  {0:c}", sumOrderTotal);
                    Console.WriteLine();
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void PrintCustomersOrderTotalLess500()
        {
            var customers = DataLoader.LoadCustomers();
            var OrderTotalLess500customers = customers.Where(c => c.Orders.Sum(order => order.Total) < 500.00M).ToList();

            PrintCustomerInformation(OrderTotalLess500customers);
        }
Пример #9
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var WashingtonCustomers = DataLoader.LoadCustomers();

            WashingtonCustomers = WashingtonCustomers.Where(p => p.Region == "WA").ToList();
            PrintCustomerInformation(WashingtonCustomers);
        }
Пример #10
0
        /// <summary>
        /// Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        /// </summary>
        static void Exercise21()
        {
            List <Customer> customers = DataLoader.LoadCustomers();

            var filtered = customers.Select(o => new { o.CompanyName, o.Orders });

            foreach (var customer in filtered)
            {
                Console.WriteLine(customer.CompanyName);
                int year = 0;

                foreach (var order in customer.Orders.ToArray())
                {
                    if (year != order.OrderDate.Year)
                    {
                        Console.WriteLine(order.OrderDate.Year);
                        year = order.OrderDate.Year;
                    }

                    Console.WriteLine($"\t{order.OrderDate.Month,2} - ${order.Total,4:#.00}");
                }

                Console.WriteLine();
            }
        }
Пример #11
0
        /// <summary>
        /// Print the Company Name and most recent order for each customer in Washington
        /// </summary>
        static void Exercise13()
        {
            List <Customer> customers = DataLoader.LoadCustomers();

            string[] titles = { "CompanyName", "OrderDate" };
            string   format = Utilities.GenerateProductFormat(titles, false);

            var query = customers
                        .Where(c => c.Region == "WA")
                        .Select(c => new
            {
                Company = c.CompanyName,
                Recent  = c.Orders
                          .OrderByDescending(o => o.OrderDate)
                          .First()
                          .OrderDate
                          .ToString("yyyy/MM/dd")
            }
                                );

            Utilities.GenerateProductHeaders(titles);

            foreach (var line in query)
            {
                Console.WriteLine(format, line.Company, line.Recent);
            }
        }
Пример #12
0
        /// <summary>
        /// Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        /// </summary>

        static void Exercise21()
        {
            var customers = DataLoader.LoadCustomers();

            foreach (var customer in customers)
            {
                Console.WriteLine(customer.CompanyName);
                Console.WriteLine("---------------------------------------------------------");

                //1. PRINT THE NAME OF THE COMPANY ONCE
                //group each customers list of orders by year
                var ordersByYear = from order in customer.Orders
                                   group order by order.OrderDate.Year;

                //2. lIST ALL ORDERS BY YEAR
                foreach (var order in ordersByYear)
                {
                    Console.WriteLine(order.Key); // this will print the year
                    var ordersByMonth = from order1 in order
                                        group order1 by order1.OrderDate.Month;

                    //3. LIST ALL ORDERS BY MONTH AND SUM MONTHLY TOTAL
                    foreach (var o in ordersByMonth)
                    {
                        var monthsum = o.Sum(x => x.Total);                          //sums each month total

                        Console.WriteLine("{0}" + " - " + "{1:c}", o.Key, monthsum); // prints the month and month sum

                        Console.WriteLine();
                    }
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            List <Customer> customers = DataLoader.LoadCustomers();
            //var waRegion = customers.Where(x => x.Region == "WA").ToList();

            List <Customer> waRegion = (from x in customers
                                        where x.Region == "WA"
                                        select x).ToList();

            foreach (var customer in waRegion)
            {
                Console.WriteLine("==============================================================================");
                Console.WriteLine(customer.CompanyName);
                Console.WriteLine(customer.Address);
                Console.WriteLine("{0}, {1} {2} {3}", customer.City, customer.Region, customer.PostalCode, customer.Country);
                Console.WriteLine("p:{0} f:{1}", customer.Phone, customer.Fax);
                Console.WriteLine();
                Console.WriteLine("\tOrders");
                foreach (var order in customer.Orders)
                {
                    Console.WriteLine("\t{0} {1:MM-dd-yyyy} {2,10:c}", order.OrderID, order.OrderDate, order.Total);
                }
                Console.WriteLine("==============================================================================");
                Console.WriteLine();
            }
        }
Пример #14
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            List <Customer> rain = DataLoader.LoadCustomers();
            var             cust = from c in rain
                                   select new
            {
                customer   = c,
                OrderTotal = c.Orders.Sum(o => o.Total)
            };

            var whatever = cust.Where(c => c.OrderTotal < 500.00M);

            foreach (var customer in whatever)
            {
                Console.WriteLine("==============================================================================");
                Console.WriteLine(customer.customer.CompanyName);
                Console.WriteLine(customer.customer.Address);
                Console.WriteLine("{0}, {1} {2} {3}", customer.customer.City, customer.customer.Region, customer.customer.PostalCode, customer.customer.Country);
                Console.WriteLine("p:{0} f:{1}", customer.customer.Phone, customer.customer.Fax);
                Console.WriteLine();
                Console.WriteLine("\tOrders");
                foreach (var order in customer.customer.Orders)
                {
                    Console.WriteLine("\t{0} {1:MM-dd-yyyy} {2,10:c}", order.OrderID, order.OrderDate, order.Total);
                }
                Console.WriteLine("==============================================================================");
                Console.WriteLine();
            }
        }
Пример #15
0
        /// <summary>
        /// Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        /// </summary>
        static void Exercise21()
        {
            var customers = DataLoader.LoadCustomers();

            var print = customers.Select(c => new {
                c.CompanyName,
                orders = c.Orders.OrderBy(o => o.OrderDate.Month).GroupBy(o => o.OrderDate.Year)
            });


            foreach (var c in print)
            {
                Console.WriteLine(c.CompanyName);
                foreach (var o in c.orders)
                {
                    Console.WriteLine(o.Key);
                    foreach (var m in o)
                    {
                        //Console.WriteLine(m.OrderDate);
                        Console.WriteLine("  " + m.OrderDate.Month + " -   " + m.Total);
                    }
                }
                Console.WriteLine();
            }
        }
Пример #16
0
        /// Print all customer and their order information for the Washington (WA) region.
        static void Exercise3()
        {
            List <Customer> customers = DataLoader.LoadCustomers();
            var             filtered  = customers.Where(c => c.Region == "WA");

            PrintCustomerInformation(filtered);
        }
Пример #17
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var customers = DataLoader.LoadCustomers();
            var cInWA     = customers.Where(c => c.Region == "WA");

            PrintCustomerInformation(cInWA);
        }
Пример #18
0
        /// Print only customers that have an order who's total is less than $500
        static void Exercise10()
        {
            List <Customer> customers = DataLoader.LoadCustomers();
            var             filtered  = customers.Where(c => c.Orders.Any(ordervalue => ordervalue.Total < 500));

            PrintCustomerInformation(filtered);
        }
Пример #19
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void PrintAllWACustomers()
        {
            var customers   = DataLoader.LoadCustomers();
            var WAcustomers = customers.Where(c => c.Region != null && c.Region.ToUpper() == "WA").ToList();

            PrintCustomerInformation(WAcustomers);
        }
Пример #20
0
        /// <summary>
        /// Print all Customers with their orders by Year then Month
        /// ex:
        ///
        /// Joe's Diner
        /// 2015
        ///     1 -  $500.00
        ///     3 -  $750.00
        /// 2016
        ///     2 - $1000.00
        ///
        /// David indicated we'd be doing a groupBy on an anonymous type made up of more than one property (e.g. day,month,year)
        /// </summary>
        static void Exercise21()
        {
            var cstmr         = DataLoader.LoadCustomers();
            var custOrderDate = from c in cstmr
                                select new
            {
                c.CompanyName,
                orderTotals = c.Orders.GroupBy(o => new
                {
                    year  = o.OrderDate.Year,
                    month = o.OrderDate.Month
                })
                              .Select(g => new
                {
                    year       = g.Key.year,
                    month      = g.Key.month,
                    orderTotal = g.Sum(o => o.Total)
                })
            };

            foreach (var whatever in custOrderDate)
            {
                Console.WriteLine(whatever.CompanyName);

                foreach (var orderData in whatever.orderTotals)
                {
                    Console.WriteLine(orderData);
                }
            }
        }
Пример #21
0
        //3. Find all customers in Washington, print their name then their orders. (Region == "WA")
        private static void problem3()
        {
            var customers = DataLoader.LoadCustomers();

            var results = from c in customers
                          where c.Region == "WA"
                          select new
            {
                Name = c.CustomerID,
                c.Region,
                Orders = from o in c.Orders
                         orderby o.OrderID
                         select new { ID = o.OrderID, Date = o.OrderDate }
            };

            foreach (var r in results)
            {
                Console.WriteLine("{0} from {1} has the following orders:", r.Name, r.Region);

                foreach (var o in r.Orders)
                {
                    Console.WriteLine("\t{0} -- {1:d}", o.ID, o.Date);
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Create and print an anonymous type containing CustomerId and the count of their orders
        /// </summary>
        static void Exercise27()
        {
            var customers = from cID in DataLoader.LoadCustomers()
                            select new
            {
                cID   = cID.CustomerID,
                Count = cID.Orders
            };

            foreach (var customerID in customers)
            {
                Console.WriteLine("{0}", customerID.cID);

                List <Customer> custOrder = new List <Customer>();

                foreach (var order in customerID.Count)
                {
                    custOrder.Add(new Customer());
                }
                int count = (from number in custOrder
                             select number).Count();

                Console.WriteLine(count);
            }
        }
Пример #23
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var customers = DataLoader.LoadCustomers();

            var customerInfoandRegion = customers.Where(c => c.Region == "WA").Select(c => c);

            PrintCustomerInformation(customerInfoandRegion);
        }
Пример #24
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var customers = DataLoader.LoadCustomers();

            var orderLess500 = customers.Where(c => c.Orders.Any(o => o.Total < 500));

            PrintCustomerInformation(orderLess500);
        }
Пример #25
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var WARegion = DataLoader.LoadCustomers().Where(p => p.Region == "WA");

            PrintCustomerInformation(WARegion);

            //done
        }
Пример #26
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var customer = DataLoader.LoadCustomers();

            var cheapCustomer = customer.Where(c => c.Orders.Sum(o => o.Total) < 501 && c.Orders.Any());

            PrintCustomerInformation(cheapCustomer);
        }
Пример #27
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var results = from customer in DataLoader.LoadCustomers()
                          where customer.Orders.Length > 0 && customer.Orders.Min(o => o.Total < 500)
                          select customer;

            PrintCustomerInformation(results);
        }
Пример #28
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var customers = from c in DataLoader.LoadCustomers()
                            where c.Orders.Any(o => o.Total < 500)
                            select c;

            PrintCustomerInformation(customers);
        }
Пример #29
0
        /// <summary>
        /// Print only customers that have an order whos total is less than $500
        /// </summary>
        static void Exercise10()
        {
            var allCustomers = DataLoader.LoadCustomers();

            allCustomers.Where(o => o.Orders.Any(total => total.Total < 500M));

            PrintCustomerInformation(allCustomers);
        }
Пример #30
0
        /// <summary>
        /// Print all customer and their order information for the Washington (WA) region.
        /// </summary>
        static void Exercise3()
        {
            var washingtonCustomers = from customer in DataLoader.LoadCustomers()
                                      where customer.Region == "WA"
                                      select customer;

            PrintCustomerInformation(washingtonCustomers);
        }