Пример #1
0
        public AddAccountResponse AddAccount(AddAccountRequest request)
        {
            AddAccountResponse response = new AddAccountResponse();

            response.Errors = new List <string>();
            if (_accountRepository.GetAccountByEmail(request.Email) != null)
            {
                response.Success = false;
                response.Errors.Add("Email Already exists");
                return(response);
            }
            _accountRepository.AddAccount(request.Email, request.Password);
            response.Success = true;
            return(response);
        }
        public AddAccountResponse AddAccount(string accountNumber, string name, string accountType)
        {
            AddAccountResponse response = new AddAccountResponse();

            if (_accountRepository.List().Any(n => n.AccountNumber == accountNumber))
            {
                response.Success = false;
                response.Message = "Error: Account number entered is already an account.\nAccount Numbers must be unique";
                return(response);
            }

            response.account = new Account();

            switch (accountType)
            {
            case "F":
            case "FREE":
                response.account.Type = AccountType.Free;
                break;

            case "B":
            case "BASIC":
                response.account.Type = AccountType.Basic;
                break;

            case "P":
            case "PREMIUM":
                response.account.Type = AccountType.Premium;
                break;

            default:
                response.Success = false;
                response.Message = $"Error: {accountType} is not a valid account type.";
                return(response);
            }

            response.Success = true;
            response.account.AccountNumber = accountNumber;
            response.account.Name          = name;

            _accountRepository.Add(response.account);
            _accountRepository.SaveAccount(response.account);

            return(response);
        }
Пример #3
0
        public void Execute()
        {
            AccountManager manager = AccountManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("::::::::::Add Account:::::::::");
            Console.WriteLine(ConsoleIO.DividingBar);
            string accountNumber = ConsoleIO.GetStringInputFromUser("Enter new account number: ");
            string name          = ConsoleIO.GetStringInputFromUser("Enter new account holder's name: ");
            string accountType   = ConsoleIO.GetStringInputFromUser("Account types: \nF - Free \nB - Basic \nP - Premium \nEnter Account Type: ").ToUpper();

            //PRINT INFO AND ASK IF CORRECT
            Console.WriteLine("NEW ACCOUNT");
            Console.WriteLine(ConsoleIO.DividingBar);
            Console.WriteLine($"Account Number: {accountNumber}");
            Console.WriteLine($"Account Name: {name}");
            Console.WriteLine($"Account Type: {accountType}");
            Console.WriteLine(ConsoleIO.DividingBar);
            ConsoleIO.GetYesNoAnswerFromUser("\nIs this information correct?(Y/N)");


            //TRY TO ADD ACCOUNT
            AddAccountResponse response = manager.AddAccount(accountNumber, name, accountType);

            if (response.Success)
            {
                Console.WriteLine("Account Added!");
                ConsoleIO.DisplayAccountDetails(response.account);
                if (response.account.Type == AccountType.Premium)
                {
                    Console.WriteLine($"{response.account.Name} receives a free Toast-O-Matic Toaster with new Premium account!");
                }
            }
            else
            {
                Console.WriteLine("An error occured: ");
                Console.WriteLine(response.Message);
            }

            Console.WriteLine("\nPress any key to continue...");
            Console.ReadKey();
        }