コード例 #1
0
        static void Main(string[] args)
        {
            Person person1 = new Person("Garold", "Cash", "*****@*****.**");
            Person person2 = new Person("Vitya", "Bove", "*****@*****.**");

            AccountNumberGenerator generator      = new AccountNumberGenerator();
            Repository             repository     = new Repository();
            AccountService         accountService = new AccountService(repository);

            accountService.OpenAccount(person1, AccountType.PlatinumAccount, generator);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.WithDraw(accountService.GetId(), 10000);
            accountService.WithDraw(accountService.GetId(), 10000);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.OpenAccount(person1, AccountType.GoldAccount, generator);


            accountService.OpenAccount(person2, AccountType.PlatinumAccount, generator);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.Deposite(accountService.GetId(), 10000);
            // accountService.Deposite(accountService.GetId(), 10000);
            accountService.WithDraw(accountService.GetId(), 10000);
            accountService.WithDraw(accountService.GetId(), 10000);
            accountService.Deposite(accountService.GetId(), 10000);
            accountService.OpenAccount(person2, AccountType.GoldAccount, generator);
        }
        public CheckingAccount GenerateCheckingAccount(string[] accountArgs)
        {
            string  accountNumber = AccountNumberGenerator.GenerateAccountNumber();
            decimal balance       = decimal.Parse(accountArgs[0]);
            decimal fee           = decimal.Parse(accountArgs[1]);

            CheckingAccount checkingAccount = new CheckingAccount(accountNumber, balance, fee);

            IValidationResult validationResult = CheckingAccountValidator.IsValid(checkingAccount);

            if (!validationResult.IsValid)
            {
                throw new ArgumentException(string.Join($"{Environment.NewLine}", validationResult.ValidationErrors));
            }

            return(checkingAccount);
        }
コード例 #3
0
        public SavingsAccount GenerateSavingAccount(string[] accountArgs)
        {
            string  accountNumber = AccountNumberGenerator.GenerateAccountNumber();
            decimal balance       = decimal.Parse(accountArgs[0]);
            decimal interestRate  = decimal.Parse(accountArgs[1]);

            SavingsAccount savingsAccount = new SavingsAccount(accountNumber, balance, interestRate);

            IValidationResult validationResult = SavingAccountValidator.IsValid(savingsAccount);

            if (!validationResult.IsValid)
            {
                throw new ArgumentException(string.Join($"{Environment.NewLine}", validationResult.ValidationErrors));
            }

            return(savingsAccount);
        }
コード例 #4
0
        public async Task <ActionResult <BankAccountModel> > PostBankAccountModel()
        {
            var BankAccount = new BankAccountModel
            {
                AccountNumber = AccountNumberGenerator.GetAccountNumber(),
                Balance       = 0,
                IsActive      = true,
                UserId        = Int32.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value),
                Settings      = new AccountSettings {
                    DailyOperationLimit = 10000, MaxDailyOperationsNumber = 15, SingleOperationLimit = 5000
                },
            };

            _context.BankAccounts.Add(BankAccount);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBankAccountModel", new { id = BankAccount.Id }, BankAccount));
        }
コード例 #5
0
        private static void CreateCustomer()
        {
            bool temp          = true;
            int  accountNumber = AccountNumberGenerator.GenerateUniqueAccountNumber(Customers);

            Console.WriteLine("What is your forename");
            var foreName = Console.ReadLine();

            Console.WriteLine("What is your surname");
            var surName = Console.ReadLine();

            Console.WriteLine("What is your address");
            var address = Console.ReadLine();
            var email   = "";

            while (temp)
            {
                Console.WriteLine("What is your email");
                string femail = Console.ReadLine();
                bool   hold   = CheckEmail(femail);

                if (hold == true)
                {
                    email = femail;
                    temp  = false;
                }
                else
                {
                    Console.WriteLine("Email invalid. Please try again");
                }
            }
            Console.WriteLine("Account created");
            Console.WriteLine("Your account number is {0}", accountNumber);
            var newCustomer = new Customer(accountNumber, foreName, surName, address, email);
            var newAccount  = new Account(accountNumber);

            Customers.Add(newCustomer);
            Accounts.Add(newAccount);
        }
コード例 #6
0
        public string Execute(string[] input)
        {
            if (input.Length != 3)
            {
                throw new ArgumentException("Input is not valid!");
            }

            // Add SavingAccount <initial balance> <interest rate>
            if (!AuthenticationManager.IsAuthenticated())
            {
                throw new InvalidOperationException("You should log in first!");
            }

            string accountType = input[0];

            string  accountNumber = AccountNumberGenerator.GenerateAccountNumber();
            decimal balance       = decimal.Parse(input[1]);
            decimal rateOrFee     = decimal.Parse(input[2]);

            // Check type of account to add and throw exception if type is not valid.
            if (accountType.Equals("CheckingAccount", StringComparison.OrdinalIgnoreCase))
            {
                CheckingAccount checkingAccount = new CheckingAccount()
                {
                    AccountNumber = accountNumber,
                    Balance       = balance,
                    Fee           = rateOrFee
                };

                ValidationResult valresult = this.CheckingAccountValidator.IsValid(checkingAccount);

                if (!valresult.IsValid)
                {
                    throw new ArgumentException(string.Join("\n", valresult.ValidationErrors));
                }

                using (BankSystemContext context = new BankSystemContext())
                {
                    // Attaching currently logged-in user means that we are working with the same user entity as in our database.
                    User user = AuthenticationManager.GetCurrentUser();
                    context.Users.Attach(user);
                    checkingAccount.User = user;

                    context.CheckingAccounts.Add(checkingAccount);
                    context.SaveChanges();
                }
            }
            else if (accountType.Equals("SavingAccount", StringComparison.OrdinalIgnoreCase))
            {
                SavingAccount savingAccount = new SavingAccount()
                {
                    AccountNumber = accountNumber,
                    Balance       = balance,
                    InterestRate  = rateOrFee
                };

                ValidationResult valresult = this.SavingAccountValidator.IsValid(savingAccount);

                if (!valresult.IsValid)
                {
                    throw new ArgumentException(string.Join("\n", valresult.ValidationErrors));
                }

                using (BankSystemContext context = new BankSystemContext())
                {
                    User user = AuthenticationManager.GetCurrentUser();
                    context.Users.Attach(user);
                    savingAccount.User = user;

                    context.SavingAccounts.Add(savingAccount);
                    context.SaveChanges();
                }
            }
            else
            {
                throw new ArgumentException($"Invalid account type {accountType}!");
            }

            return($"Account with number {accountNumber} successfully added.");
        }
コード例 #7
0
        public void TestRandomStringGenerator()
        {
            string random = AccountNumberGenerator.GenerateUniqueString(10);

            Assert.IsTrue(!"[^a-zA-Z]".Contains(random));
        }
コード例 #8
0
 static void Main(string[] args)
 {
     Console.WriteLine(AccountNumberGenerator.GenerateCurrent());
     Console.Read();
 }