示例#1
0
 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");
         }
     });
 }