Example #1
0
        /// <summary>
        /// Handle input.
        /// </summary>
        public void InputLoop()
        {
            var inputOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;

            do
            {
                Console.Write("\n\n");
                var line = CliInput.GetLine(inputOptions, v => true, "Sort by [D]ate / [P]rice / [S]tore\nor enter an order number to view details:");
                switch (line)
                {
                case "D":
                case "d":
                    this.SortKey = this.SortKey != OrderSortKey.DateDesc ? OrderSortKey.DateDesc : OrderSortKey.DateAsc;
                    break;

                case "P":
                case "p":
                    this.SortKey = this.SortKey != OrderSortKey.PriceDesc ? OrderSortKey.PriceDesc : OrderSortKey.PriceAsc;
                    break;

                case "S":
                case "s":
                    this.SortKey = this.SortKey != OrderSortKey.LocationAsc ? OrderSortKey.LocationAsc : OrderSortKey.LocationDesc;
                    break;

                default:
                    if (line == "" || line == null)
                    {
                        this.MenuExit();
                        return;
                    }
                    try
                    {
                        var orderNum = Int32.Parse(line);
                        if (orderNum > 0 && orderNum <= this.OrderIds.Count)
                        {
                            using (var db = new StoreContext(this.ApplicationState.DbOptions))
                            {
                                var order         = db.GetOrderById(this.OrderIds[orderNum - 1]);
                                var amountCharged = db.GetAmountCharged(order);
                                this.DisplayDetail(db, order, amountCharged);
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception) {
                        // We will just ignore parse errors and reprint the menu.
                        break;
                    }
                }
                this.PrintMenu();
            } while (true);
        }
Example #2
0
        /// <summary>
        /// Handle the input when viewing a list of all orders for a location.
        /// </summary>
        /// <returns>A <c>HandlerMsg</c> indicating what action should be taken.</returns>
        private HandlerMsg HandleViewOrderInput()
        {
            var inputOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;

            do
            {
                var line = CliInput.GetLine(inputOptions, v => true, "\nSort by [D]ate / [P]rice\nor enter an order number to view details:");
                switch (line)
                {
                case "D":
                case "d":
                    this.SortKey = this.SortKey != OrderSortKey.DateDesc ? OrderSortKey.DateDesc : OrderSortKey.DateAsc;
                    break;

                case "P":
                case "p":
                    this.SortKey = this.SortKey != OrderSortKey.PriceDesc ? OrderSortKey.PriceDesc : OrderSortKey.PriceAsc;
                    break;

                default:
                    if (line == "" || line == null)
                    {
                        this.CurrentOperatingMode = OperatingMode.SelectLocation;
                        return(HandlerMsg.Continue);
                    }
                    try
                    {
                        var orderNum = Int32.Parse(line);
                        if (orderNum > 0 && orderNum <= this.OrderIds.Count)
                        {
                            using (var db = new StoreContext(this.ApplicationState.DbOptions))
                            {
                                var order         = db.GetOrderById(this.OrderIds[orderNum - 1]);
                                var amountCharged = db.GetAmountCharged(order);
                                this.DisplayDetail(db, order, amountCharged);
                                break;
                            }
                        }
                        else
                        {
                            CliPrinter.Error("Invalid order number");
                            continue;
                        }
                    }
                    catch (Exception) {
                        // We will just ignore parse errors and reprint the menu.
                        break;
                    }
                }
                this.PrintMenu();
            } while (true);
        }
Example #3
0
        /// <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;
            }
        }
Example #4
0
        /// <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;
                }
            }
        }