Example #1
0
        public BankAccount Deposit(BankAccountModel accountModel, decimal amount, string currency)
        {
            using (ChilindoBankLtdDB context = new ChilindoBankLtdDB())
            {
                bool saveFailed = false;

                var account = context.BankAccounts
                              .Where(a => a.AccountNumber.Equals(accountModel.AccountNumber))
                              .FirstOrDefault();
                do
                {
                    try
                    {
                        saveFailed       = false;
                        account.Balance += amount;
                        context.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        saveFailed = true;

                        ex.Entries.Single().Reload();
                    }
                    catch (Exception e)
                    {
                        //handle and log exception here.
                    }
                } while (saveFailed);

                return(account);
            }
        }
        public RequestResponse CreateResponse(BankAccountModel bankAccount, bool successful = true, string message = "")
        {
            if (bankAccount == null)
            {
                return(null);
            }

            return(new RequestResponse
            {
                AccountNumber = bankAccount.AccountNumber,
                Successful = successful,
                Balance = bankAccount.Balance,
                Currency = bankAccount.Currency,
                Message = message
            });
        }