Exemplo n.º 1
0
        /// <summary>
        /// Print this menu.
        /// </summary>
        public void PrintMenu()
        {
            Console.Clear();
            CliPrinter.Title("Order Items");
            this.ApplicationState.UserData.RefreshCurrentOrder();

            if (this.ApplicationState.UserData.CurrentOrderId == null)
            {
                using (var db = new StoreContext(this.ApplicationState.DbOptions))
                {
                    var customer = db.GetCustomerById(this.ApplicationState.UserData.CustomerId);
                    var location = db.GetLocationById(this.ApplicationState.UserData.OperatingLocationId);
                    var order    = new Order(customer, location);
                    order.Customer = customer;
                    db.Add(order);
                    db.SaveChanges();
                    this.ApplicationState.UserData.CurrentOrderId = order.OrderId;
                }
            }

            using (var db = new StoreContext(this.ApplicationState.DbOptions))
            {
                var inventory = db.GetProductsAvailable(this.ApplicationState.UserData.OperatingLocationId);

                var order = db.GetOrderById(this.ApplicationState.UserData.CurrentOrderId);

                var i = 1;
                this.InventoryIds = inventory.Select(i => i.LocationInventoryId).ToList();
                Console.WriteLine("#\tStock\tName");
                foreach (var stock in inventory)
                {
                    var projectedQuantity = db.ProjectStockBasedOnOrder(order, stock.Product);
                    if (projectedQuantity < 0)
                    {
                        projectedQuantity = 0;
                    }
                    Console.WriteLine($"{i}.\t{projectedQuantity}\t{stock.Product.Name}");
                    i += 1;
                }
                Console.Write("\n----------------------------------------------\n");
            }
        }
        /// <summary>
        /// Print this menu.
        /// </summary>
        public void PrintMenu()
        {
            Console.Clear();
            CliPrinter.Title("Edit Order");
            this.ApplicationState.UserData.RefreshCurrentOrder();

            this.LineItemIds.Clear();

            using (var db = new StoreContext(this.ApplicationState.DbOptions))
            {
                var order = db.GetOrderById(this.ApplicationState.UserData.CurrentOrderId);
                if (order == null)
                {
                    return;
                }
                if (order.OrderLineItems.Count() == 0)
                {
                    return;
                }
                var itemNameDividerSize = order.OrderLineItems.Max(li => li.Product.Name.Length);
                Console.WriteLine("#\tQty\tEach\tTotal\tName");
                Console.WriteLine($"===\t===\t=====\t=====\t{new string('=', itemNameDividerSize)}");

                double orderTotalCost  = 0.0;
                int    orderTotalUnits = 0;
                foreach (var o in order.OrderLineItems)
                {
                    this.LineItemIds.Add(o.OrderLineItemId);
                    var lineItemTotal = o.Product.Price * o.Quantity;
                    orderTotalCost  += lineItemTotal;
                    orderTotalUnits += o.Quantity;
                    Console.WriteLine($"{this.LineItemIds.Count}\t{o.Quantity}\t${o.Product.Price}\t${lineItemTotal}\t{o.Product.Name}");
                }

                Console.WriteLine($"---\t-----\t-----\t-----\t{new string('-', itemNameDividerSize)}");
                Console.Write($"\t{orderTotalUnits}\t\t${orderTotalCost}\tTotal\n\n");
            }
        }
        /// <summary>
        /// Print this menu.
        /// </summary>
        public void PrintMenu()
        {
            Console.Clear();
            CliPrinter.Title("Find Customer");
            this.DisplaySearchTerm(this.SearchQuery);
            Console.SetCursorPosition(0, SearchResultTerminalRow);

            DisplaySearchTerm(this.SearchQuery);

            ClearResults();

            Console.SetCursorPosition(0, SearchResultTerminalRow);
            Console.WriteLine("=============================");

            if (this.SearchQuery.Length == 0)
            {
                return;
            }

            var maxResults = Console.WindowHeight - SearchResultTerminalRow - 4;

            using (var db = new StoreDb.StoreContext(this.ApplicationState.DbOptions))
            {
                var customers     = db.FindCustomerByName(this.SearchQuery);
                var displayAmount = customers.Count() > maxResults ? maxResults : customers.Count();
                Console.Write($"{customers.Count()} customers found. Displaying {displayAmount}.\n\n");
                foreach (var customer in customers.Take(displayAmount).OrderBy(c => c.FirstName))
                {
                    var phoneNumber = customer.PhoneNumber;
                    if (phoneNumber == null || phoneNumber == "")
                    {
                        phoneNumber = "            ";
                    }
                    Console.WriteLine($"{phoneNumber}: {customer.FirstName} {customer.LastName}");
                }
            }
        }
 /// <summary>
 /// Print this menu.
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Review Order");
     this.ApplicationState.UserData.RefreshCurrentOrder();
 }
 /// <summary>
 /// Print this menu.
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Create Account");
 }
Exemplo n.º 6
0
 /// <summary>
 /// Print this menu
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Login");
 }
Exemplo n.º 7
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;
            }
        }
 /// <summary>
 /// Prints this menu.
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Add New Location");
 }
 /// <summary>
 /// Print this menu.
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Add new customer");
 }
Exemplo n.º 10
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;
                }
            }
        }
 /// <summary>
 /// Print this menu.
 /// </summary>
 public void PrintMenu()
 {
     Console.Clear();
     CliPrinter.Title("Select store");
 }