/// <summary>
        /// Handle input.
        /// </summary>
        public void InputLoop()
        {
            var cliOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;

            do
            {
                var login = CliInput.GetLine(cliOptions, CliInput.EmailValidator, "Email:");
                if (login == "" || login == null)
                {
                    this.MenuExit();
                    return;
                }

                var password = CliInput.GetPassword("Password:"******"Invalid login.");
                }
            } while (true);
            this.ApplicationState.UserData.RefreshDefaultLocation();
        }
示例#2
0
        /// <summary>
        /// Handle the input when selecting a location to query for orders.
        /// </summary>
        /// <returns>A <c>HandlerMsg</c> indicating what action should be taken.</returns>
        private HandlerMsg HandleSelectLocationInput()
        {
            var inputOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;

            do
            {
                var line = CliInput.GetLine(inputOptions, v => true, "Select location number:");
                if (line == "" || line == null)
                {
                    return(HandlerMsg.Exit);
                }
                try
                {
                    var locationNumber = Int32.Parse(line);
                    if (locationNumber > 0 && locationNumber <= this.LocationIds.Count)
                    {
                        this.SelectedLocation     = this.LocationIds[locationNumber - 1];
                        this.CurrentOperatingMode = OperatingMode.ViewOrders;
                        return(HandlerMsg.Continue);
                    }
                }
                catch
                {
                    CliPrinter.Error("Please enter a valid location number.");
                }
            } while (true);
        }
示例#3
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);
        }
示例#4
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);
        }
        /// <summary>
        /// Handle input.
        /// </summary>
        public void InputLoop()
        {
            do
            {
                this.PrintMenu();
                if (this.ApplicationState.UserData.CurrentOrderId == null)
                {
                    CliInput.PressAnyKey("There is currently no open order.");
                    break;
                }
                using (var db = new StoreContext(this.ApplicationState.DbOptions))
                {
                    var order = db.GetOrderById(this.ApplicationState.UserData.CurrentOrderId);
                    if (order == null)
                    {
                        break;
                    }
                    if (order.OrderLineItems.Count() == 0)
                    {
                        CliInput.PressAnyKey("There are no items in your order.");
                        break;
                    }
                }

                var getLineOptions = CliInput.GetLineOptions.AcceptEmpty | CliInput.GetLineOptions.TrimSpaces;
                var option         = CliInput.GetLine(getLineOptions, v => true, "[D]elete / Change [Q]uantity: ");
                switch (option)
                {
                case null:
                case "":
                    this.MenuExit();
                    return;

                case "D":
                case "d":
                {
                    var itemNumber = CliInput.GetInt(CliInput.GetIntOptions.AllowEmpty, n => n > 0 && n <= this.LineItemIds.Count, "Select item number:");
                    if (itemNumber == null)
                    {
                        continue;
                    }

                    using (var db = new StoreContext(this.ApplicationState.DbOptions))
                    {
                        var deleted = db.DeleteLineItem(this.LineItemIds[(int)itemNumber - 1]);
                        if (!deleted)
                        {
                            CliInput.PressAnyKey("There was a problem deleting that line item. Please try again.");
                        }
                    }
                    break;
                }

                case "Q":
                case "q":
                {
                    var itemNumber = CliInput.GetInt(CliInput.GetIntOptions.AllowEmpty, n => n > 0 && n <= this.LineItemIds.Count, "Select item number:");
                    if (itemNumber == null)
                    {
                        continue;
                    }

                    using (var db = new StoreContext(this.ApplicationState.DbOptions))
                    {
                        var order = db.GetOrderById(this.ApplicationState.UserData.CurrentOrderId);

                        var lineItemId = this.LineItemIds[(int)itemNumber - 1];
                        var lineItem   = order.OrderLineItems.Where(li => li.OrderLineItemId == lineItemId);

                        var product = lineItem.First().Product;


                        var maxOrder = db.LocationInventories
                                       .Where(i => i.Location.LocationId == order.Location.LocationId)
                                       .Where(i => i.Product.ProductId == product.ProductId)
                                       .Select(i => i.Quantity).FirstOrDefault();

                        var newQuantity = CliInput.GetInt(CliInput.GetIntOptions.AllowEmpty,
                                                          q => q >= 0 && q <= maxOrder,
                                                          $"New quantity [{maxOrder} max]:");

                        if (newQuantity == null)
                        {
                            continue;
                        }

                        var adjusted = db.SetLineItemQuantity(this.LineItemIds[(int)itemNumber - 1], (int)newQuantity);
                        if (!adjusted)
                        {
                            CliInput.PressAnyKey("There was a problem adjusting the quantity for that line item. Please try again.");
                        }
                    }
                    break;
                }
                }
            } while (true);
            this.MenuExit();
        }
        /// <summary>
        /// Handle user input.
        /// </summary>
        public void InputLoop()
        {
            string EmailLoop(DbContextOptions <StoreContext> dbOptions)
            {
                var    cliOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;
                string login      = "";

                do
                {
                    login = CliInput.GetLine(cliOptions, CliInput.EmailValidator, "Email Address:");

                    if (login == "" || login == null)
                    {
                        return(null);
                    }

                    if (dbOptions.LoginExists(login))
                    {
                        CliPrinter.Error("That email address is already in use.");
                    }
                    else
                    {
                        break;
                    }
                } while (true);
                return(login);
            }

            do
            {
                var cliOptions = CliInput.GetLineOptions.TrimSpaces | CliInput.GetLineOptions.AcceptEmpty;

                var firstName = CliInput.GetLine(cliOptions, Customer.ValidateName, "First Name:");

                if (firstName == "" || firstName == null)
                {
                    this.AbortThenExit("Empty entry - exiting.");
                    return;
                }

                var lastName = CliInput.GetLine(cliOptions, Customer.ValidateName, "Last Name:");
                if (lastName == "" || lastName == null)
                {
                    this.AbortThenExit("Empty entry - exiting.");
                    return;
                }
                var login = EmailLoop(this.ApplicationState.DbOptions);
                if (login == "" || login == null)
                {
                    this.AbortThenExit("Empty entry - exiting.");
                    return;
                }

                var password = CliInput.GetPassword("Password:"******"")
                {
                    this.AbortThenExit("Empty entry - exiting.");
                    return;
                }
                var customer = new Customer();
                // Data pre-validated above.
                customer.FirstName = firstName;
                customer.LastName  = lastName;
                customer.Login     = login;
                customer.Password  = password;

                var createResult = this.ApplicationState.DbOptions.CreateUserAccount(customer);

                if (createResult == CreateUserAccountResult.Ok)
                {
                    this.ApplicationState.UserData.CustomerId = customer.CustomerId;
                    this.MenuExit();
                    this.MenuAdd(new StoreCliMenuUser.Main(this.ApplicationState));
                    CliInput.PressAnyKey("\nAccount created.");
                    break;
                }
                else
                {
                    CliPrinter.Error("An error occurred while creating your account. Please try again.");
                }
            } while (true);
        }