Beispiel #1
0
        /// <summary>
        /// Adds credits (stregdollars) to a user based on the username and amount of credit
        /// </summary>
        /// <param name="args"></param>
        public void HandleAddCreditToUser(List <string> args)
        {
            User user   = _stregsystem.GetUserByUsername(args[0]);
            int  amount = int.Parse(args[1]);

            _stregsystem.AddCreditsToAccount(user, amount);
        }
        void InsertMoney <AdminMethod>(string nula, string username, string amount)
        {
            try
            {
                User    user             = GetUser(username);
                decimal _amount          = Convert.ToDecimal(amount);
                InsertCashTransaction tr = Stregsystem.AddCreditsToAccount(user, _amount);

                UI.DisplayUserInfo(user);
            }
            catch (UserNotFoundException e)
            {
                UI.DisplayUserNotFound(e.username);
            }
            catch (ArgumentNullException)
            {
                UI.DisplayUserNotFound(username);
            }
            catch (FormatException)
            {
                UI.DisplayQuantityMustBeANumber();
            }
            catch (OverflowException)
            {
                UI.DisplayQuantityMustBeANumber();
            }
            catch (Exception e)
            {
                UI.DisplayGeneralError(e.Message);
            }
        }
Beispiel #3
0
        void AdminstrationCommand(string[] commandlist) // I am aware that this collides with the requested dictionary definition, however i could simply not make it work
        {
            int argsCount = commandlist.Length;

            switch (commandlist[0]) // a switch over AdminCommands, this will if the commands are typed in a valid manner, and if it is, a relevant function will be called
            {
            case ":quit":           // if commands is either q or quit, UI.close will be called to effectivly end the session
            case ":q":
                if (argsCount == 1)
                {
                    UI.Close();
                }
                else
                {
                    UI.DisplayGeneralError("q or quit command can only be 1 arg");
                }
                break;

            case ":activate":     // if commands is either activate or deactivate, SetActiveStatus will be called in order to change the value of Product.Active
            case ":deactivate":
                if (argsCount == 2)
                {
                    pointsystem.SetActiveStatus(commandlist[0], commandlist[1]);
                }
                else
                {
                    UI.DisplayGeneralError("Command can only be 2 args: status and productID");
                }
                break;

            case ":crediton":     // If commands is either crediton or creditoff, SetCreditStatus will be called in order to change the value of Product.CanBeBoughtOnCredit
            case ":creditoff":
                if (argsCount == 2)
                {
                    pointsystem.SetCreditStatus(commandlist[0], commandlist[1]);
                }
                else
                {
                    UI.DisplayGeneralError("Command can only be 2 args: status and productID");
                }
                break;

            case ":addcredits":     // If addcredits helper function is called, and UI will load a new feedbackLine
                if (argsCount == 3)
                {
                    pointsystem.AddCreditsToAccount(commandlist[2], Int32.Parse(commandlist[1]));
                    UI.DisplayCreditsAdded(commandlist[2], Int32.Parse(commandlist[1]));
                }
                else
                {
                    UI.DisplayGeneralError("Command can only be 3 args, :addcredits, amount and user");
                }
                break;

            default:
                UI.DisplayAdminCommandNotFoundMessage(commandlist.ToString());     // command was not in a recoqnized format
                break;
            }
        }
Beispiel #4
0
 /// <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());
 }
Beispiel #6
0
        private void InsertCashTransaction(string username, int amount)
        {
            User user = _stregsystem.GetUserByUsername(username);

            if (user != null)
            {
                if (amount > 0)
                {
                    InsertCashTransaction iCT = _stregsystem.AddCreditsToAccount(user, amount);
                    _ui.DisplayTransaction(iCT);
                }
                else
                {
                    _ui.DisplayGeneralError("Cannot insert negative cash.");
                }
            }
        }
Beispiel #7
0
 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");
         }
     });
 }