예제 #1
0
        public Response<DeleteReceipt> Delete(int accountNumber)
        {
            var repo = new AccountRepository();
            var response = new Response<DeleteReceipt>();

            try
            {
                var account = repo.GetAllAccounts();

                if (account == null)
                {
                    response.Success = false;
                    response.Message = "Account was not found!";
                }
                else
                {
                    response.Success = true;
                    repo.OverwriteFile(account, accountNumber);
                }
            }
            catch (Exception ex)
            {
                // log the exception
                response.Success = false;
                response.Message = "There was an error.  Please try again later.";
            }

            return response;
        }
예제 #2
0
        public Response Deposit(Account account, decimal Amount)
        {
            var response = new Response();

            if (Amount > 0)
            {
                account.Balance += Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(account);

                response.Success = true;
                response.Message = "You have successfully made a deposit.";
                response.DepositInfo = new DepositSlip();
                response.DepositInfo.AccountNumber = account.AccountNumber;
                response.DepositInfo.DepositAmount = Amount;
                response.DepositInfo.NewBalance = account.Balance;

            }
            else
            {
                response.Success = false;
                response.Message = "WTF You have to give a positive amount to deposit!";
            }

            return response;
        }
예제 #3
0
        public Response CreateAccount()
        {
            AccountRepository repo = new AccountRepository();
            Account newAccount = new Account();
            Response response = new Response();

            newAccount.AccountNumber = 1;
            Console.Write("Account holder First name :");
            newAccount.FirstName = Console.ReadLine();
            Console.Write("Account holder Last name :");
            newAccount.LastName = Console.ReadLine();

            newAccount.Balance = 0.00M;

             int returnedAccountNumber = repo.WriteNewLine(newAccount);

            if (returnedAccountNumber == repo.GetAllAccounts().Count)
            {
                response.Success = true;

                response.CreateAccountInfo = new CreateAccountSlip();
                response.CreateAccountInfo.AccountNumber = returnedAccountNumber;
                response.CreateAccountInfo.FirstName = newAccount.FirstName;
                response.CreateAccountInfo.LastName = newAccount.LastName;
                response.CreateAccountInfo.NewBalance = newAccount.Balance;

            }
            else
            {
                response.Success = false;
                response.Message = "The account was not created, please try again.";
            }

            return response;
        }
예제 #4
0
        public Response<Account> MakeDeposit(DepositRequest request)
        {
            var response = new Response<Account>();
            var accountToUpdate = request.Account;

            try
            {
                if (request.DepositAmount <= 0)
                {
                    response.Success = false;
                    response.Message = "Must deposit a positive amount.";
                }
                else
                {
                    accountToUpdate.Balance += request.DepositAmount;

                    var repo = new AccountRepository();
                    repo.UpdateAccount(accountToUpdate);
                    response.Success = true;
                    response.Data = accountToUpdate;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #5
0
        public Response<Account> GetAccount(string accountNumber)
        {
            var repo = new AccountRepository();
            var response = new Response<Account>();

            try
            {
                var account = repo.GetAccount(accountNumber);

                if (account == null)
                {
                    response.Success = false;
                    response.Message = "Account Not Found!";
                }
                else
                {
                    response.Success = true;
                    response.Data = account;
                }

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #6
0
        public Response<Account> DeleteAccount(DeleteAccountRequest request)
        {
            var response = new Response<Account>();
            var accountToDelete = request.Account;

            try
            {

                if (accountToDelete == null)
                {
                    response.Success = false;
                    response.Message = "Account Not Found!";
                }
                else
                {
                    var repo = new AccountRepository();
                    repo.DeleteAccount(accountToDelete);
                    response.Success = true;
                }

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #7
0
        public Response<Account> CreateAccount(CreateAccountRequest request)
        {
            var response = new Response<Account>();
            var newAccount = request.Account;

            var repo = new AccountRepository();
            repo.CreateAccount(newAccount);
            response.Success = true;
            response.Data = newAccount;

            return response;
        }
예제 #8
0
        public Response<CreateReceipt> Create(string[] newAccount)
        {
            AccountRepository repo = new AccountRepository();
            var response = new Response<CreateReceipt>();

            var allAccounts = repo.GetAllAccounts();
            List<int> accountNums = new List<int>();

            foreach (var accout in allAccounts)
            {
               accountNums.Add(accout.AccountNumber);
            }

            int freshAccountNumber = accountNums.Max() + 1;

            try
            {
                if (Decimal.Parse(newAccount[2]) <= 0)
                {
                    response.Success = false;
                    response.Message = "Must initially deposit a positive value.";
                }
                else
                {
                    response.Data = new CreateReceipt();
                    response.Data.AccountNumber = freshAccountNumber;
                    response.Data.FirstName = newAccount[0];
                    response.Data.LastName = newAccount[1];
                    response.Data.InitalAmount = Decimal.Parse(newAccount[2]);
                    response.Success = true;
                    response.Message = "Account successfully created.  Press any key to continue...";
                    repo.CreateAccount(response);
                }
            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #9
0
        public Response GetAccount(int AccountNumber)
        {
            var repo = new AccountRepository();
            var response = new Response();

            var account = repo.GetAccount(AccountNumber);

            if (account == null)
            {
                response.Success = false;
                response.Message = "This is not the Account you are looking for...";
            }
            else
            {
                response.Success = true;
                response.AccountInfo = account;
            }
            return response;
        }
예제 #10
0
        public Response Transfer(Account Account1, Account Account2, decimal Amount)
        {
            var response = new Response();

            if (Amount <= Account1.Balance && Amount > 0)
            {
                Account1.Balance -= Amount;
                Account2.Balance += Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(Account1, Account2);

                response.Success = true;
                response.Message = "You have successfully made a transfer.";
                response.TransferInfo = new TransferSlip();
                response.TransferInfo.CurrentAccountNumber = Account1.AccountNumber;
                response.TransferInfo.CurrentAccountName = Account1.FirstName + " " + Account1.LastName;
                response.TransferInfo.TargetAccountNumber = Account2.AccountNumber;
                response.TransferInfo.TargetAccountName = Account2.FirstName + " " + Account2.LastName;
                response.TransferInfo.TransferAmount = Amount;
                response.TransferInfo.NewBalanceCurrentAccount = Account1.Balance;
                response.TransferInfo.NewBalanceTargetAccount = Account2.Balance;
            }
            else
            {
                response.Success = false;
                if (Amount > Account1.Balance)
                {
                    response.Message = "You cannot transfer more money than you have in your balance!!";
                }
                else
                {
                    response.Message = "That is not a proper transfer amount.";
                }
            }

            return response;
        }
예제 #11
0
        public Response<WithdrawReciept> Withdraw(Account account, decimal amount)
        {
            var response = new Response<WithdrawReciept>();

            try
            {
                if (amount <= 0 )
                {
                    response.Success = false;
                    response.Message = "Must withdraw a positive value.";
                }
                else if (amount > account.Balance)
                {
                    response.Success = false;
                    response.Message = "Insufficient Funds";
                }
                else
                {
                    account.Balance -= amount;
                    var repo = new AccountRepository();
                    repo.UpdateAccount(account);
                    response.Success = true;

                    response.Data = new WithdrawReciept();
                    response.Data.AccountNumber = account.AccountNumber;
                    response.Data.WithdrawAmount = amount;
                    response.Data.NewBalance = account.Balance;
                }
            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #12
0
        public Response<Account> MakeWithDrawal(WithDrawalRequest request)
        {
            var response = new Response<Account>();
            var accountToUpdate = request.Account;

            try
            {
                if (request.Account.Balance < request.WithdrawalAmount)
                {
                    response.Success = false;
                    response.Message = "You do not have adequate funds in your account.";

                }
                else
                {
                    accountToUpdate.Balance -= request.WithdrawalAmount;

                    var repo = new AccountRepository();
                    repo.UpdateAccount(accountToUpdate);
                    response.Success = true;
                    response.Data = accountToUpdate;

                }

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #13
0
        public Response Withdraw(Account account, decimal Amount)
        {
            var response = new Response();

            if (Amount > account.Balance)
            {
                response.Success = false;
                response.Message = " Insufficent funds";
            }
            else
            {
                account.Balance -= Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(account);

                response.Success = true;
                response.WithdrawInfo = new WithdrawSlip();
                response.WithdrawInfo.AccountNumber = account.AccountNumber;
                response.WithdrawInfo.WithdrawalAmount = Amount;
                response.WithdrawInfo.NewBalance = account.Balance;

            }
            return response;
        }
예제 #14
0
        public Response<DepositReciept> Deposit(Account account, decimal amount)
        {
            var response = new Response<DepositReciept>();

            try
            {
                if (amount <= 0)
                {
                    response.Success = false;
                    response.Message = "Must deposit a positive value.";
                }
                else
                {
                    account.Balance += amount;
                    var repo = new AccountRepository();
                    repo.UpdateAccount(account);
                    response.Success = true;

                    response.Data = new DepositReciept();
                    response.Data.AccountNumber = account.AccountNumber;
                    response.Data.DepositAmount = amount;
                    response.Data.NewBalance = account.Balance;
                }
            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #15
0
 public Response Transfer()
 {
     Response response = new Response();
     return response;
 }
예제 #16
0
 public void CreateAccount(Response<CreateReceipt> toCreate)
 {
     string createNewInfo = Environment.NewLine + toCreate.Data.AccountNumber + "," + toCreate.Data.FirstName + "," +
                            toCreate.Data.LastName + "," + toCreate.Data.InitalAmount;
     File.AppendAllText(FilePath, createNewInfo);
 }
예제 #17
0
        public Response<Account> GetAccount(int accountNumber)
        {
            var repo = new AccountRepository();
            var response = new Response<Account>();

            try
            {
                var account = repo.LoadAccount(accountNumber);

                if (account == null)
                {
                    response.Success = false;
                    response.Message = "Account was not found!";
                }
                else
                {
                    response.Success = true;
                    response.Data = account;
                }
            }
            catch (Exception ex)
            {
                // log the exception
                response.Success = false;
                response.Message = "There was an error.  Please try again later.";
            }

            return response;
        }
예제 #18
0
        public Response<TransferReceipt> Transfer(Account accountFrom, Account accountTo, decimal amount)
        {
            var response = new Response<TransferReceipt>();

            try
            {
                if (amount <= 0)
                {
                    response.Success = false;
                    response.Message = "Must transfer a positive value.";
                }
                else
                {
                    accountFrom.Balance -= amount;
                    accountTo.Balance += amount;
                    var repoFrom = new AccountRepository();
                    repoFrom.UpdateAccount(accountFrom);
                    repoFrom.UpdateAccount(accountTo);
                    response.Success = true;

                    response.Data = new TransferReceipt();
                    response.Data.AccountNumberFrom = accountFrom.AccountNumber;
                    response.Data.TransferAmount = amount;
                    response.Data.NewBalance = accountFrom.Balance;

                    response.Data = new TransferReceipt();
                    response.Data.AccountNumberTo = accountTo.AccountNumber;
                    response.Data.TransferAmount = amount;
                    response.Data.NewBalance = accountTo.Balance;
                }
            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
예제 #19
0
 private void PrintAccountDetails(Response<Account> response)
 {
     Console.WriteLine("Account Information");
     Console.WriteLine("=============================");
     Console.WriteLine("Account Number: {0}", response.Data.AccountNumber);
     Console.WriteLine("Name : {0} {1}", response.Data.FirstName, response.Data.LastName);
     Console.WriteLine("Account Balance: {0:c}", response.Data.Balance);
 }
예제 #20
0
        public Response Withdraw(Account account, decimal Amount)
        {
            var response = new Response();

            if (Amount <= account.Balance && Amount > 0)
            {
                account.Balance -= Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(account);

                response.Success = true;
                response.Message = "You have successfully made a withdrawal.";
                response.WithdrawalInfo = new WithdrawalSlip();
                response.WithdrawalInfo.AccountNumber = account.AccountNumber;
                response.WithdrawalInfo.WithdrawalAmount = Amount;
                response.WithdrawalInfo.NewBalance = account.Balance;
            }
            else
            {
                response.Success = false;
                if (Amount > account.Balance)
                {
                    response.Message = "You cannot withdraw more money than you have in your balance!!";
                }
                else
                {
                    response.Message = "That is not a proper withdrawal amount.";
                }
            }

            return response;
        }