/// <summary> /// Method to populate the dictionary with admin commands /// </summary> private void PopulateAdminCommands() { _adminCommands.Add(":q", c => _ui.Close()); _adminCommands.Add(":quit", c => _ui.Close()); _adminCommands.Add(":activate", c => _s.GetProductByID(int.Parse(c[0])).Active = true); _adminCommands.Add(":deactivate", c => _s.GetProductByID(int.Parse(c[0])).Active = false); _adminCommands.Add(":crediton", c => _s.GetProductByID(int.Parse(c[0])).CanBeBoughtOnCredit = true); _adminCommands.Add(":creditoff", c => _s.GetProductByID(int.Parse(c[0])).CanBeBoughtOnCredit = false); _adminCommands.Add(":addcredits", c => _s.AddCreditsToAccount(_s.GetUserByUsername(c[0]), int.Parse(c[1]))); }
// All the admin commands and what they do public void AddAdminCommands() { AdminCommands.Add(":activate", args => _stregsystem.GetProductByID(int.Parse(args[1])).Active = true); AdminCommands.Add(":addcredits", args => _stregsystem.AddCreditsToAccount(_stregsystem.GetUserByUsername(args[1]), decimal.Parse(args[2]))); AdminCommands.Add(":deactivate", args => _stregsystem.GetProductByID(int.Parse(args[1])).Active = false); AdminCommands.Add(":creditoff", args => _stregsystem.GetProductByID(int.Parse(args[1])).CanBeBoughtOnCredit = false); AdminCommands.Add(":crediton", args => _stregsystem.GetProductByID(int.Parse(args[1])).CanBeBoughtOnCredit = true); AdminCommands.Add(":q", args => _ui.Close()); AdminCommands.Add(":quit", args => _ui.Close()); }
public StregsystemController(IStregsystemUI stregsystemCLI, IStregsystem stregsystem) { _stregsystem = stregsystem; _stregsystemUI = stregsystemCLI; _stregsystemUI.CommandEntered += ParseCommand; _admincommands.Add(":q", (List <string> args) => stregsystemCLI.Close()); _admincommands.Add(":quit", (List <string> args) => stregsystemCLI.Close()); _admincommands.Add(":activate", (List <string> args) => HandleActiveProduct(args)); _admincommands.Add(":deactivate", (List <string> args) => HandleDeactiveProduct(args)); _admincommands.Add(":crediton", (List <string> args) => HandleCreditOn(args)); _admincommands.Add(":creditoff", (List <string> args) => HandleCreditOff(args)); }
public void AddAdminCommands() { adminCommands = new Dictionary <string, Action <string[]> >() { { ":quit", (command) => ui.Close() }, { ":q", (command) => ui.Close() }, { ":activate", (command) => ChangeProductStatus(command, true) }, { ":deactivate", (command) => ChangeProductStatus(command, false) }, { ":crediton", (command) => ChangeProductCreditStatus(command, true) }, { ":creditoff", (command) => ChangeProductCreditStatus(command, false) }, { ":addcredits", (command) => AddCreditToUser(command) } }; }
public StregsystemController(IStregsystemUI stregsystemCLI, IStregsystem stregsystem) { _stregsystem = stregsystem; _stregystemui = stregsystemCLI; _stregystemui.CommandEntered += ParseCommand; _adminCommands.Add(":q", (List <string> args) => stregsystemCLI.Close()); _adminCommands.Add(":quit", (List <string> args) => stregsystemCLI.Close()); _adminCommands.Add(":activate", (List <string> args) => HandleActivateProduct(args)); //method for handling activation _adminCommands.Add(":deactivate", (List <string> args) => HandleDeactivateProduct(args)); _adminCommands.Add(":crediton", (List <string> args) => HandlePurchaseableOnCredit(args)); //method for handling product able to purchased on credit _adminCommands.Add(":creditoff", (List <string> args) => HandleNotPurchaseableOnCredit(args)); _adminCommands.Add(":addcredits", (List <string> args) => HandleAddCreditToUser(args)); //method for handling adding credits }
public StregsystemController(IStregsystemUI stregsystemCLI, IStregsystem stregsystem) { _stregsystem = stregsystem; _stregsystemUI = stregsystemCLI; _stregsystemUI.CommandEntered += ParseCommand; _stregsystem.UserBalanceWarning += _stregsystemUI.DisplayUserLowOnMoney; _admincommands.Add(":q", (List <string> args) => stregsystemCLI.Close()); _admincommands.Add(":quit", (List <string> args) => stregsystemCLI.Close()); _admincommands.Add(":activate", (List <string> args) => HandleActiveProduct(args)); _admincommands.Add(":deactivate", (List <string> args) => HandleDeactiveProduct(args)); _admincommands.Add(":crediton", (List <string> args) => HandleCreditOn(args)); _admincommands.Add(":creditoff", (List <string> args) => HandleCreditOff(args)); _admincommands.Add(":addcredits", (List <string> args) => HandleAddCreditToUser(args)); }
public StregsystemCommandParser(Stregsystem stregsystem, IStregsystemUI ui) { this.stregsystem = stregsystem; this.ui = ui; MakeTempUsers(); adminFunctions = new Dictionary <string, Action <string> >(); adminFunctions.Add(":q", str => ui.Close()); adminFunctions.Add(":quit", str => ui.Close()); adminFunctions.Add(":activate", productID => stregsystem.GetProduct(Convert.ToInt32(productID)).Active = true); adminFunctions.Add(":deactivate", productID => stregsystem.GetProduct(Convert.ToInt32(productID)).Active = false); adminFunctions.Add(":crediton", productID => stregsystem.GetProduct(Convert.ToInt32(productID)).CanBeBoughtOnCredit = true); adminFunctions.Add(":creditoff", productID => stregsystem.GetProduct(Convert.ToInt32(productID)).CanBeBoughtOnCredit = false); adminFunctions.Add(":addcredits", usernameAndAmount => stregsystem.AddCreditsToAccount(Convert.ToInt32(usernameAndAmount.Split()[1]), usernameAndAmount.Split()[0])); adminFunctions.Add(":makeuser", userDetails => MakeUser(userDetails)); adminFunctions.Add(":help", str => adminFunctions.Keys.ToList().ForEach(key => ui.DisplayMessage(key))); }
private void Quit <AdminMethod>(string nula, string nulb, string nulc) { try { Stregsystem.WriteToLogFile(); UI.Close(); return; } catch (System.IO.IOException e) { UI.DisplayGeneralError(e.Message); } catch { //hvis der ikke er noget at gøre så luk ui og crash UI.Close(); throw new Exception(); } return; }
private void AddAdminCommands() { _adminCommands.Add(":quit", (string[] command) => { TestArgumentNumber(command, 1); SUI.Close(); }); _adminCommands.Add(":q", (string[] command) => { TestArgumentNumber(command, 1); SUI.Close(); }); _adminCommands.Add(":activate", (string[] command) => { TestArgumentNumber(command, 2); S.GetProductByID(Convert.ToInt32(command[1])).Active = true; }); _adminCommands.Add(":deactivate", (string[] command) => { TestArgumentNumber(command, 2); S.GetProductByID(Convert.ToInt32(command[1])).Active = false; }); _adminCommands.Add(":crediton", (string[] command) => { TestArgumentNumber(command, 2); S.GetProductByID(Convert.ToInt32(command[1])).CanBeBoughtOnCredit = true; }); _adminCommands.Add(":creditoff", (string[] command) => { TestArgumentNumber(command, 2); S.GetProductByID(Convert.ToInt32(command[1])).CanBeBoughtOnCredit = false; }); _adminCommands.Add(":addcredits", (string[] command) => { TestArgumentNumber(command, 3); SUI.DisplayInserCashTransation(S.AddCreditsToAccount(S.GetUserByUsername(command[1]), Convert.ToInt32(command[2]))); }); }
public void FillAdminCommands() { _adminCommands.Add(":q", () => ui.Close()); _adminCommands.Add(":quit", () => ui.Close()); _adminCommands.Add(":activate", () => { try { if (ProductSuccess(int.Parse(_command.Split(" ")[1]))) { Product p = ss.GetProductByID(int.Parse(_command.Split(" ")[1])); if (p is SeasonalProduct) { ui.DisplayGeneralError($"{p.name} is a seasonal product"); return; } p.active = true; Console.WriteLine($"{p.name} has been activated"); } } catch (FormatException) { ui.DisplayGeneralError($"{_command.Split(" ")[1]} is not a positive integer"); } }); _adminCommands.Add(":deactivate", () => { try { if (ProductSuccess(int.Parse(_command.Split(" ")[1]))) { Product p = ss.GetProductByID(int.Parse(_command.Split(" ")[1])); if (p is SeasonalProduct) { ui.DisplayGeneralError($"{p.name} is a seasonal product"); return; } p.active = false; Console.WriteLine($"{p.name} has been deactivated"); } } catch (FormatException) { ui.DisplayGeneralError($"{_command.Split(" ")[1]} is not a positive integer"); } }); _adminCommands.Add(":crediton", () => { try { if (ProductSuccess(int.Parse(_command.Split(" ")[1]))) { Product p = ss.GetProductByID(int.Parse(_command.Split(" ")[1])); if (p is SeasonalProduct) { ui.DisplayGeneralError($"{p.name} is a seasonal product"); return; } p.canBeBoughtOnCredit = true; Console.WriteLine($"{p.name} can now be bought on credit"); } } catch (FormatException) { ui.DisplayGeneralError($"{_command.Split(" ")[1]} is not a positive integer"); } }); _adminCommands.Add(":creditoff", () => { try { if (ProductSuccess(int.Parse(_command.Split(" ")[1]))) { Product p = ss.GetProductByID(int.Parse(_command.Split(" ")[1])); if (p is SeasonalProduct) { ui.DisplayGeneralError($"{p.name} is a seasonal product"); return; } p.canBeBoughtOnCredit = false; Console.WriteLine($"{p.name} can now not be bought on credit"); } } catch (FormatException) { ui.DisplayGeneralError($"{_command.Split(" ")[1]} is not a positive integer"); } }); _adminCommands.Add(":addcredits", () => { try { if (UserSucess(_command.Split(" ")[1])) { User u = ss.GetUserByUsername(_command.Split(" ")[1]); ss.LogTransaction(ss.AddCreditsToAccount(u, int.Parse(_command.Split(" ")[2])), @"C:\Users\T-Phamz\Desktop\test.txt"); Console.WriteLine($"{_command.Split(" ")[2]} credits has been added to {u.username}"); } } catch (SystemException) { ui.DisplayGeneralError($"{_command.Split(" ")[2]} is not a positive integer"); } }); }
private void AdminCommand(string commandparameters) { string[] parameters = commandparameters.Split(' '); string command = parameters[0]; parameters[0] = parameters[0].ToLower(); Dictionary <string, Action> adminCommands = new Dictionary <string, Action>(); switch (parameters.Length) { case 1: adminCommands.Add(":q", () => _ui.Close()); adminCommands.Add(":quit", () => _ui.Close()); adminCommands.Add(":help", () => _ui.ShowHelp()); if (adminCommands.ContainsKey(command)) { adminCommands[command](); } else { _ui.DisplayAdminCommandNotFoundMessage(commandparameters); } break; case 2: int id = int.Parse(parameters[1]); adminCommands.Add(":active", () => SetProductActive(id, true)); adminCommands.Add(":deactive", () => SetProductActive(id, false)); adminCommands.Add(":crediton", () => SetProductCredit(id, true)); adminCommands.Add(":creditoff", () => SetProductCredit(id, false)); Product product = _stregsystem.GetProductByID(id); if (product != null) { if (adminCommands.ContainsKey(command)) { adminCommands[command](); } else { _ui.DisplayAdminCommandNotFoundMessage(commandparameters); } } else { _ui.DisplayProductNotFound(id.ToString()); } break; case 3: string userName = parameters[1]; int credit = int.Parse(parameters[2]); adminCommands.Add(":addcredits", () => InsertCashTransaction(userName, credit)); User user = _stregsystem.GetUserByUsername(userName); if (user != null) { if (adminCommands.ContainsKey(command)) { adminCommands[command](); } else { _ui.DisplayAdminCommandNotFoundMessage(commandparameters); } } else { _ui.DisplayUserNotFound(userName); } break; default: _ui.DisplayAdminCommandNotFoundMessage(commandparameters); break; } }