Пример #1
0
        //Execute the admincommands, again using the number of arguments given.
        private void PraseAdminCommand(string command)
        {
            var commandArgumets = command.Split(' ').ToList();

            try
            {
                switch (commandArgumets.Count)
                {
                case 1:
                    _adminCommands[commandArgumets[0]](String.Empty, 0);
                    break;

                case 2:
                    _adminCommands[commandArgumets[0]](string.Empty, Convert.ToInt32(commandArgumets[1]));
                    break;

                case 3:
                    _adminCommands[commandArgumets[0]](commandArgumets[1], Convert.ToInt32(commandArgumets[2]));
                    break;
                }
            }
            catch (KeyNotFoundException)
            {
                _ui.DisplayAdminCommandNotFoundMessage(command);
            }
            catch (UserNotFoundException ex)
            {
                _ui.DisplayUserNotFound(ex.Username);
            }
            catch (ProductNotFoundException ex)
            {
                _ui.DisplayProductNotFound(ex.ProductId.ToString());
            }
        }
Пример #2
0
        public CommandParser(LineSystem lineSystem, ILineSystemUI ui)
        {
            LineSystem = lineSystem;
            UI = ui;

            adminCommands.Add(":close", args => UI.Close());
            adminCommands.Add(":activate", args =>
            {
                ChangeProductBoolField(":activate", args, ProductBoolField.Active, true);
            });
            adminCommands.Add(":deactivate", args =>
            {
                ChangeProductBoolField(":deactivate", args, ProductBoolField.Active, false);
            });
            adminCommands.Add(":crediton", args =>
            {
                ChangeProductBoolField(":crediton", args, ProductBoolField.CanBeBoughtOnCredit, true);
            });
            adminCommands.Add(":creditoff", args =>
            {
                ChangeProductBoolField(":creditoff", args, ProductBoolField.CanBeBoughtOnCredit, false);
            });
            adminCommands.Add(":addcredits", args =>
            {
                InsertCashTransaction transaction;
                User user;
                int amount;

                if (IsValidArgs(":addcredits", args, 2))
                {
                    user = LineSystem.GetUser(args[0]);

                    if (user != null)
                    {
                        if (args[1].TryToCredit(out amount))
                        {
                            transaction = LineSystem.AddCreditsToAccount(user, amount);
                            UI.DisplayAdminAddedCredits(transaction);
                            LineSystem.ExecuteTransaction(transaction);
                        }
                        else
                        {
                            UI.DisplayGeneralError(args[1] + " is not a invalid cash amount");
                        }
                    }
                    else
                    {
                        UI.DisplayUserNotFound(args[0]);
                    }
                }
            });
        }
Пример #3
0
        public CommandParser(LineSystem lineSystem, ILineSystemUI ui)
        {
            LineSystem = lineSystem;
            UI         = ui;

            adminCommands.Add(":close", args => UI.Close());
            adminCommands.Add(":activate", args =>
            {
                ChangeProductBoolField(":activate", args, ProductBoolField.Active, true);
            });
            adminCommands.Add(":deactivate", args =>
            {
                ChangeProductBoolField(":deactivate", args, ProductBoolField.Active, false);
            });
            adminCommands.Add(":crediton", args =>
            {
                ChangeProductBoolField(":crediton", args, ProductBoolField.CanBeBoughtOnCredit, true);
            });
            adminCommands.Add(":creditoff", args =>
            {
                ChangeProductBoolField(":creditoff", args, ProductBoolField.CanBeBoughtOnCredit, false);
            });
            adminCommands.Add(":addcredits", args =>
            {
                InsertCashTransaction transaction;
                User user;
                int amount;

                if (IsValidArgs(":addcredits", args, 2))
                {
                    user = LineSystem.GetUser(args[0]);

                    if (user != null)
                    {
                        if (args[1].TryToCredit(out amount))
                        {
                            transaction = LineSystem.AddCreditsToAccount(user, amount);
                            UI.DisplayAdminAddedCredits(transaction);
                            LineSystem.ExecuteTransaction(transaction);
                        }
                        else
                        {
                            UI.DisplayGeneralError(args[1] + " is not a invalid cash amount");
                        }
                    }
                    else
                    {
                        UI.DisplayUserNotFound(args[0]);
                    }
                }
            });
        }