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);
            }
        }
예제 #2
0
        /// <summary>
        /// Handles user commands
        /// </summary>
        /// <param name="commandArray"></param>
        private void ParseUserCommand(string[] commandArray)
        {
            switch (commandArray.Length)
            {
            case 1:
                _ui.DisplayUserInfo(_s.GetUserByUsername(commandArray[0]));
                break;

            case 2:
                _ui.DisplayUserBuysProduct(
                    _s.BuyProduct(_s
                                  .GetUserByUsername(commandArray[0]), _s
                                  .GetProductByID(int.Parse(commandArray[1]))));
                break;

            case 3:
                _ui.DisplayUserBuysProduct(int.Parse(commandArray[1]), _s.BuyProduct(
                                               _s.GetUserByUsername(commandArray[0]),
                                               _s.GetProductByID(int.Parse(commandArray[2]))));

                int numberOfProducts = int.Parse(commandArray[1]) - 1;

                for (int i = 1; i < numberOfProducts; i++)
                {
                    _s.BuyProduct(
                        _s.GetUserByUsername(commandArray[0]),
                        _s.GetProductByID(int.Parse(commandArray[2])));
                }
                break;
            }
        }
        public void ParseCommand(string command)
        {
            string[] commandParts = command.Split(' ');

            if (command != string.Empty)
            {
                if (command[0] == ':')
                {
                    ExecuteAdminCommand(commandParts);
                }
                else if (ValidCommand(commandParts))
                {
                    try
                    {
                        if (commandParts.Count() == 3)
                        {
                            ui.DisplayUserBuysProduct(stregsystem.BuyProduct(Convert.ToInt32(commandParts[2]), Convert.ToInt32(commandParts[1]), commandParts[0]));
                        }
                        else if (commandParts.Count() == 2)
                        {
                            ui.DisplayUserBuysProduct(stregsystem.BuyProduct(Convert.ToInt32(commandParts[1]), commandParts[0]));
                        }
                        else if (commandParts.Count() == 1)
                        {
                            ui.DisplayUserInfo(stregsystem.GetUser(commandParts[0]));
                        }
                        else
                        {
                            ui.DisplayTooManyArgumentsError();
                        }
                    }
                    catch (Exception e)
                    {
                        if (e is UserNotFoundException)
                        {
                            ui.DisplayUserNotFound(commandParts[0]);
                        }
                        else if (e is InsufficientCreditsException)
                        {
                            ui.DisplayError("Insufficient funds.");
                        }
                    }
                }
                else
                {
                    ui.DisplayError("Not a valid command");
                }
            }
            else
            {
                ui.DisplayError("You must type a command.");
            }
        }
예제 #4
0
        public void HandleUserInput(List <string> commandInputs)
        {
            if ((commandInputs.Count == 1) || (Regex.IsMatch(commandInputs[1], @"^[1-9 ]\d*$")))
            {
                switch (commandInputs.Count)
                {
                case 1:
                {
                    User user = null;
                    try
                    {
                        user = _stregsystem.GetUserByUsername(commandInputs[0]);
                    }
                    catch (UserNotFoundException)
                    {
                        _stregystemui.DisplayUserNotFound(commandInputs[0]);
                        return;
                    }
                    _stregystemui.DisplayUserInfo(user);
                    _stregystemui.DisplayPastTransactions(user);
                    break;
                }

                case 2:
                {
                    HandlePurchase(commandInputs[0], int.Parse(commandInputs[1]), 1);
                    break;
                }

                case 3:
                {
                    HandlePurchase(commandInputs[0], int.Parse(commandInputs[1]), int.Parse(commandInputs[2]));
                    break;
                }

                default:
                {
                    _stregystemui.DisplayGeneralError("Der skete en fejl, tjek om syntax er korrekt.");
                    break;
                }
                }
            }
            else
            {
                _stregystemui.DisplayuProductNotFound(commandInputs[1]);
                return;
            }
        }
예제 #5
0
 void HandleUserCommand(string username)
 {
     try
     {
         User user = _stregsystem.GetUserByUsername(username);
         IEnumerable <Transaction> transactions = _stregsystem.GetTransactions(user, 10);
         _stregsystemUI.DisplayUserInfo(user.ToString() + $"Saldo: {user.Balance * 0.01f}");
         foreach (Transaction t in transactions)
         {
             _stregsystemUI.DisplayTransaction(t);
         }
     }
     catch (UserNotFoundException)
     {
         _stregsystemUI.DisplayUserNotFound(username);
     }
 }
예제 #6
0
        private void FindUserInfo(string username)
        {
            User user = _stregsystem.GetUserByUsername(username);

            if (user != null)
            {
                _ui.DisplayUserInfo(user);
                // maks 10 tranaktioner må vises i følge opg beskrivelsen
                IEnumerable <Transaction> userTransactions = _stregsystem.GetTransactions(user, 10);
                foreach (Transaction transaction in userTransactions)
                {
                    _ui.DisplayTransaction(transaction);
                }
                if (user.Balance < 50)
                {
                    _ui.DisplayUserBalanceWarning(user, user.Balance);
                }
            }
            else
            {
                _ui.DisplayUserNotFound(username);
            }
        }
예제 #7
0
 private void TypedInUsername(User user)
 {
     SUI.DisplayUserInfo(user);
 }
예제 #8
0
 private void DisplayUser()
 {
     _ui.DisplayUserInfo(_user);
 }
예제 #9
0
        public void DisplayUserInformation(string username)
        {
            IUser user = stregsystem.GetUserByUsername(username);

            ui.DisplayUserInfo(user);
        }
예제 #10
0
        public void ParseCommand()
        {
            _command = Console.ReadLine();
            string[] command = _command.Split(" ");

            if (command[0].StartsWith(":"))
            {
                bool success = false;
                if (_adminCommands.ContainsKey(command[0]))
                {
                    _adminCommands[command[0]].Invoke();
                    success = true;
                }
                if (success == false)
                {
                    ui.DisplayAdminCommandNotFoundMessage(_command);
                }
            }
            else if (command.Length == 2)
            {
                try
                {
                    string user      = command[0];
                    int    productID = int.Parse(command[1]);
                    if (ProductSuccess(productID) && UserSucess(user))
                    {
                        BuyTransaction buy = ss.BuyProduct(ss.GetUserByUsername(user), ss.GetProductByID(productID));
                        ss.LogTransaction(buy, @"C:\Users\T-Phamz\Desktop\test.txt");
                        ui.DisplayUserBuysProduct(buy);
                        ss.OnUserBalanceWarning(ss.GetUserByUsername(user));
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine($"{(command[1])} is not a positive integer");
                }
                catch (InsufficientCreditsException)
                {
                    ui.DisplayInsufficientCash(ss.GetUserByUsername(command[0]), ss.GetProductByID(int.Parse(command[1])));
                }
                catch (ProductNotActiveException ex)
                {
                    ui.DisplayGeneralError(ex.Message);
                }
            }
            else if (command.Length == 3)
            {
                try
                {
                    string user          = command[0];
                    int    numberOfItems = int.Parse(command[1]);
                    int    productID     = int.Parse(command[2]);
                    if (ProductSuccess(productID) && UserSucess(user) && numberOfItems > 0)
                    {
                        BuyTransaction buy = null;
                        for (int i = 0; i < numberOfItems; i++)
                        {
                            buy = ss.BuyProduct(ss.GetUserByUsername(user), ss.GetProductByID(productID));
                            ss.LogTransaction(buy, @"C:\Users\T-Phamz\Desktop\test.txt");
                        }
                        ui.DisplayUserBuysProduct(numberOfItems, buy);
                        ss.OnUserBalanceWarning(ss.GetUserByUsername(user));
                    }
                    else
                    {
                        ui.DisplayGeneralError($"Number of items bought ({command[1]}) can not be under 1");
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine($"{(command[1])} or {(command[2])} " +
                                      $"is not a number");
                }
                catch (InsufficientCreditsException)
                {
                    ui.DisplayInsufficientCash(ss.GetUserByUsername(command[0]), ss.GetProductByID(int.Parse(command[1])));
                }
                catch (ProductNotActiveException ex)
                {
                    ui.DisplayGeneralError(ex.Message);
                }
            }
            else if (command.Length == 1)
            {
                if (UserSucess(command[0]))
                {
                    User u = ss.GetUserByUsername(command[0]);
                    ui.DisplayUserInfo(u);
                    foreach (Transaction item in ss.GetTransactions(u, 10))
                    {
                        ui.DisplayTransactions(item);
                    }
                    ss.OnUserBalanceWarning(u);
                }
            }
            else
            {
                ui.DisplayTooManyArgumentsError($"\"{_command}\"");
            }
            Console.WriteLine();
        }