Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var lineSystem = new LineSystem();
            var UI = new LineSystemCLI(lineSystem);

            lineSystem.Users.Add(new User("Test", "Test", "Test", "*****@*****.**"));

            UI.Start();
        }
Exemplo n.º 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]);
                    }
                }
            });
        }
Exemplo n.º 3
0
        public LineSystemTest()
        {
            lineSystem = new LineSystem(null);
            testUser = new User("test", "test", "test", "*****@*****.**", 100000);
            
            lineSystem.Products.Add(new Product("test1", 101, true, 24));
            lineSystem.Products.Add(new Product("test2", 101, true));
            lineSystem.Products.Add(new Product("test3", 101, true));

            lineSystem.Users.Add(testUser);
            lineSystem.Users.Add(new User("test2", "test2", "test2", "[email protected]"));
            lineSystem.Users.Add(new User("test3", "test3", "test3", "[email protected]"));

            lineSystem.Transactions.Add(new BuyTransaction(DateTime.Now, testUser, new Product("test", 99, true)));
            lineSystem.Transactions.Add(new BuyTransaction(DateTime.Now, lineSystem.Users[1], new Product("test", 99, true)));
            lineSystem.Transactions.Add(new InsertCashTransaction(DateTime.Now, testUser, 100));
            lineSystem.Transactions.Add(new InsertCashTransaction(DateTime.Now, lineSystem.Users[2], 100));
            
        }
Exemplo n.º 4
0
 public LineSystemCLI(LineSystem lineSystem)
 {
     LineSystem = lineSystem;
     Parser = new CommandParser(lineSystem, this);
 }