using System.Collections.Generic;
public static class Program
public int CustomerID { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public static List<Order> GetOrders()
List<Customer> customers = Customer.ReturnCust();
new Order() {CustomerID = customers[0].ID,Description="Shoes", Price=150.23M, Quantity=1},
new Order() {CustomerID = customers[0].ID,Description="Phone", Price=130.25M, Quantity=1},
new Order() {CustomerID = customers[0].ID,Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[1].ID,Description="Phone", Price=130.25M, Quantity=1},
new Order() {CustomerID = customers[1].ID,Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[1].ID,Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[2].ID,Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[2].ID,Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[2].ID,Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[3].ID,Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[3].ID,Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[3].ID,Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[4].ID,Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[4].ID,Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[4].ID,Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[5].ID,Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[5].ID,Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[5].ID,Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[6].ID,Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[6].ID,Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[6].ID,Description="Shoes", Price=150.23M, Quantity=1},
new Order() {CustomerID = customers[7].ID,Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[7].ID,Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[7].ID,Description="Pants", Price=70.56M, Quantity=1},
public int ID { get; set; }
public int Age { get; set; }
public string First { get; set; }
public string Last { get; set; }
public static List<Customer> ReturnCust()
return new List<Customer>()
new Customer(){ID = 1, Age = 23, First = "Joe", Last = "Smith"},
new Customer(){ID = 2, Age = 34, First = "Kevin", Last = "Costner"},
new Customer(){ID = 3, Age = 23, First = "Sally", Last = "Smuthers"},
new Customer(){ID = 4, Age = 56, First = "Mary", Last = "Jane"},
new Customer(){ID = 5, Age = 48, First = "Jane", Last = "Kendall"},
new Customer(){ID = 6, Age = 34, First = "Eve", Last ="Shrimp"},
new Customer(){ID = 7, Age = 31, First = "Donna", Last = "Lynn"},
new Customer(){ID = 8, Age = 21, First = "Sarah", Last = "Spicer"},
public static void Main(string[] args)
var customers = from customer in Customer.ReturnCust()
join order in Order.GetOrders() on customer.ID equals order.CustomerID into groupCustomer
select new { name = customer.First + " " + customer.Last, orders = from or in groupCustomer
orderby or.Price descending select or };
foreach (var cust in customers)
Console.WriteLine(cust.name);
Console.WriteLine("---------------");
Console.WriteLine("\nOrders:");
foreach (var order in cust.orders)
Console.WriteLine(" " + order.Description + " " + "Price:" + order.Price + " " + "Quantity:" + order.Quantity);
Console.WriteLine("\n============================\n");
var count = Order.GetOrders().Count();
Console.WriteLine("Total Number of Orders: {0}\n", count);
var Price500orLess = Order.GetOrders().Where(o => o.Price < 500);
Console.WriteLine("Number of orders $500 or under: {0}\n", Price500orLess.Count());
var Price500orAbove = Order.GetOrders().Where(o => o.Price > 500);
Console.WriteLine("Number of orders $500 or under: {0}\n", Price500orAbove.Count());
var AllPriceOrder = Order.GetOrders().Sum(x => x.Price);
Console.WriteLine("Total cost for all orders: {0}\n", AllPriceOrder);
var leastExpensive = Order.GetOrders().GroupBy(x => new { x.Description, x.Price }).OrderBy(o => o.Key.Price).Take(3);
Console.WriteLine("\nThe 3 least expensive products :");
foreach (var order in leastExpensive)
Console.WriteLine(order.Key.Description + " " + order.Key.Price);
var mostExpensive = Order.GetOrders().GroupBy(x => new { x.Description, x.Price }).OrderByDescending(o => o.Key.Price).Take(3);
Console.WriteLine("\nThe 3 Most expensive products :");
foreach (var order in mostExpensive)
Console.WriteLine(order.Key.Description + " " + order.Key.Price);