/// <summary> /// Print this menu. /// </summary> public void PrintMenu() { Console.Clear(); CliPrinter.Title("Order History"); switch (this.CurrentOperatingMode) { case OperatingMode.SelectLocation: using (var db = new StoreContext(this.ApplicationState.DbOptions)) { var locations = db.GetLocations(); this.LocationIds.Clear(); var i = 1; foreach (var location in locations) { this.LocationIds.Add(location.LocationId); Console.WriteLine($"{i}. {location.Name}"); i += 1; } Console.WriteLine("\n"); } break; case OperatingMode.ViewOrders: using (var db = new StoreContext(this.ApplicationState.DbOptions)) { var location = db.GetLocationById(this.SelectedLocation); if (location == null) { break; } var orders = db .GetOrderHistory(location) .Select(o => new { OrderId = o.OrderId, Customer = o.Customer, Location = o.Location, TimeCreated = o.TimeCreated, TimeSubmitted = o.TimeSubmitted, TimeFulfilled = o.TimeFulfilled, AmountPaid = o.AmountPaid, OrderLineItem = o.OrderLineItems, AmountCharged = db.GetAmountCharged(o), }).ToList(); if (orders.Count() == 0) { CliPrinter.Error("There are no orders for this location."); this.CurrentOperatingMode = OperatingMode.SelectLocation; CliInput.PressAnyKey(); this.PrintMenu(); return; } var upArrow = '↑'; var downArrow = '↓'; var priceSortSymbol = '-'; var dateSortSymbol = '-'; switch (this.SortKey) { case OrderSortKey.DateDesc: orders = orders.OrderByDescending(o => o.TimeSubmitted).ToList(); dateSortSymbol = downArrow; break; case OrderSortKey.DateAsc: orders = orders.OrderBy(o => o.TimeSubmitted).ToList(); dateSortSymbol = upArrow; break; case OrderSortKey.PriceDesc: orders = orders.OrderByDescending(o => o.AmountCharged).ToList(); priceSortSymbol = downArrow; break; case OrderSortKey.PriceAsc: orders = orders.OrderBy(o => o.AmountCharged).ToList(); priceSortSymbol = upArrow; break; } var historyDisplayAlignment = "{0,-6}{1,-9}{2,-25}"; var priceSortLine = $"{priceSortSymbol}----"; var dateSortLine = $"{dateSortSymbol}---"; Console.WriteLine(historyDisplayAlignment, "Num", "Price", "Date"); Console.WriteLine(historyDisplayAlignment, "---", priceSortLine, dateSortLine); var i = 1; this.OrderIds.Clear(); foreach (var order in orders) { this.OrderIds.Add(order.OrderId); Console.WriteLine(historyDisplayAlignment, i + ".", "$" + order.AmountCharged, order.TimeSubmitted, order.Location.Name); i += 1; } } break; default: break; } }
/// <summary> /// Print this menu. /// </summary> public void PrintMenu() { Console.Clear(); CliPrinter.Title("Order History"); using (var db = new StoreContext(this.ApplicationState.DbOptions)) { var orders = db .GetOrderHistory(this.ApplicationState.UserData.CustomerId) .Select(o => new { OrderId = o.OrderId, Customer = o.Customer, Location = o.Location, TimeCreated = o.TimeCreated, TimeSubmitted = o.TimeSubmitted, TimeFulfilled = o.TimeFulfilled, AmountPaid = o.AmountPaid, OrderLineItem = o.OrderLineItems, AmountCharged = (double)db.GetAmountCharged(o), }).ToList(); var upArrow = '↑'; var downArrow = '↓'; var priceSortSymbol = '-'; var dateSortSymbol = '-'; var locationSortSymbol = '-'; switch (this.SortKey) { case OrderSortKey.DateDesc: orders = orders.OrderByDescending(o => o.TimeSubmitted).ToList(); dateSortSymbol = downArrow; break; case OrderSortKey.DateAsc: orders = orders.OrderBy(o => o.TimeSubmitted).ToList(); dateSortSymbol = upArrow; break; case OrderSortKey.PriceDesc: orders = orders.OrderByDescending(o => o.AmountCharged).ToList(); priceSortSymbol = downArrow; break; case OrderSortKey.PriceAsc: orders = orders.OrderBy(o => o.AmountCharged).ToList(); priceSortSymbol = upArrow; break; case OrderSortKey.LocationDesc: orders = orders.OrderByDescending(o => o.Location.Name).ToList(); locationSortSymbol = downArrow; break; case OrderSortKey.LocationAsc: orders = orders.OrderBy(o => o.Location.Name).ToList(); locationSortSymbol = upArrow; break; } var historyDisplayAlignment = "{0,-6}{1,-9}{2,-25}{3,-15}"; var priceSortLine = $"{priceSortSymbol}----"; var dateSortLine = $"{dateSortSymbol}---"; var locationSortLine = $"{locationSortSymbol}----"; Console.WriteLine(historyDisplayAlignment, "Num", "Price", "Date", "Store"); Console.WriteLine(historyDisplayAlignment, "---", priceSortLine, dateSortLine, locationSortLine); var i = 1; this.OrderIds.Clear(); foreach (var order in orders) { this.OrderIds.Add(order.OrderId); Console.WriteLine(historyDisplayAlignment, i + ".", "$" + order.AmountCharged, order.TimeSubmitted, order.Location.Name); i += 1; } } }