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]); } } }); }
public SystemController(ILineSystemUI ui, ILineSystem lineSystem) { this._ui = ui; this._system = lineSystem; _adminCommands.Add(":quit", (s, i) => ui.Close()); _adminCommands.Add(":q", (s, i) => ui.Close()); _adminCommands.Add(":activate", (s, productId) => { Product product = _system.GetProductByID(productId); product.Active = true; ui.DisplayAdminCommandMessage($"Product {product.Name} is set to active"); }); _adminCommands.Add(":deactivate", (s, productId) => { Product product = _system.GetProductByID(productId); product.Active = false; ui.DisplayAdminCommandMessage($"Product {product.Name} is set to deactive"); }); _adminCommands.Add(":crediton", (s, productId) => { Product product = _system.GetProductByID(productId); product.CanBeBoughtOnCredit = true; ui.DisplayAdminCommandMessage($"Product {product.Name} can now be bought on credits"); }); _adminCommands.Add(":creditoff", (s, productId) => { Product product = _system.GetProductByID(productId); product.CanBeBoughtOnCredit = false; ui.DisplayAdminCommandMessage($"Product {product.Name} cannot be bought on credit now"); }); _adminCommands.Add(":addcredits", (username, amount) => { User user = _system.GetUserByUsername(username); _system.AddCreditsToAccount(user, amount); ui.DisplayAdminCommandMessage($"{amount}DDK was added to {user.Username}'s account"); }); this._ui.CommandEntered += Ui_CommandEntered; }