Example #1
0
        public void CustomerData()
        {
            var dataFixture = new DataFixture();

            dataFixture.Fixture().ConfigureAwait(false).GetAwaiter().GetResult();

            // Initialize the list of objects and save them into database table.
            string filePath     = "\\Data\\customers.json";
            var    customersDTO = IOHelpers.ReadFromFile <Customer, CustomerDTO>(filePath, true);

            var repositoryCustomer = new RepositoryCustomer();
            var customers          = IOHelpers.EntitiesList <Customer, CustomerDTO>(customersDTO, repositoryCustomer.BusinessToDomainObjectPropertyMap());

            var customersNew = new List <Customer>();

            using (var dbContext = new BankAccountContext())
            {
                var repository = new RepositoryBaseEF <Customer>(dbContext);

                customersNew = repository.Get();
            }

            dataFixture.Dispose().ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotNull(customersNew);

            var count = customers.Count;

            Assert.Equal(customers[count - 1].BirthDate, customersNew[count - 1].BirthDate);
        }
Example #2
0
        public bool ammountcheck(int acc_id, decimal amount, int type)
        {
            BankAccountContext DbContext1      = new BankAccountContext();
            BankAccount        tempbankaccount = DbContext1.BankAccounts.Find(acc_id);

            if (type == 0)
            {
                if (tempbankaccount.balance > amount)
                {
                    tempbankaccount.balance -= amount;
                    DbContext1.Entry(tempbankaccount).State = EntityState.Modified;
                    DbContext1.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                tempbankaccount.balance += amount;
                DbContext1.Entry(tempbankaccount).State = EntityState.Modified;
                DbContext1.SaveChanges();
                return(true);
            }
        }
Example #3
0
        /// <summary>
        /// Read the list of objects from a file.
        /// </summary>
        public static List <T2> ReadFromFile <T1, T2>(string filePath, bool inputData = false)
            where T1 : EntityBase
            where T2 : EntityBase
        {
            using (var dbContext = new BankAccountContext())
            {
                var repository = new RepositoryBaseEF <T1>(dbContext);

                string json = string.Empty;

                if (repository.Get().Count <= 0 || inputData)
                {
                    // Get the current WORKING directory (i.e. \bin\Debug)
                    string workingDirectory = Directory.GetCurrentDirectory();

                    // Get the current PROJECT directory
                    string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;

                    filePath = projectDirectory + filePath;
                    json     = File.ReadAllText(filePath);
                }

                return(json == string.Empty ? new List <T2>() : Newtonsoft.Json.JsonConvert.DeserializeObject <List <T2> >(json));
            }
        }
Example #4
0
        public void AccountData()
        {
            var dataFixture = new DataFixture();

            dataFixture.Fixture().ConfigureAwait(false).GetAwaiter().GetResult();

            // Initialize the list of objects and save them into database table.
            var filePath    = "\\Data\\accounts.json";
            var accountsDTO = IOHelpers.ReadFromFile <Account, AccountDTO>(filePath, true);

            var repositoryAccount = new RepositoryAccount();
            var accounts          = IOHelpers.EntitiesList <Account, AccountDTO>(accountsDTO, repositoryAccount.BusinessToDomainObjectPropertyMap());

            var accountsNew = new List <Account>();

            using (var dbContext = new BankAccountContext())
            {
                var repository = new RepositoryBaseEF <Account>(dbContext);

                accountsNew = repository.Get();
            }

            dataFixture.Dispose().ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotNull(accountsNew);

            var count = accounts.Count;

            Assert.Equal(accounts[count - 1].AccountNo, accountsNew[count - 1].AccountNo);
        }
        public void Play_UseCase_TransferFunds()
        {
            var accountContext = new BankAccountContext(
                _accountsRegistry, checkingAccount.Id, savingsAccount.Id);

            accountContext.TransferFunds(70);

            checkingAccount.Balance.Should().Be(30);
            savingsAccount.Balance.Should().Be(70);
        }
Example #6
0
 public static void SeedDatabase(BankAccountContext context)
 {
     context.Database.Migrate();
     context.BankAccounts.AddRange(
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 1", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref1", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref1", Deposit = 300, Withdrawal = 100
             }
         }
     },
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 2", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref2", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref2", Deposit = 300, Withdrawal = 100
             }
         }
     },
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 3", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref3", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref3", Deposit = 300, Withdrawal = 100
             }
         }
     },
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 4", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref4", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref4", Deposit = 300, Withdrawal = 100
             }
         }
     },
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 5", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref5", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref5", Deposit = 300, Withdrawal = 100
             }
         }
     },
         new Model.BankAccount {
         Balance = 150, CustomerRef = "Ref 6", BankAccountId = new Guid(), Transaction = new List <Model.Transaction> {
             new Model.Transaction(300, 100, "ref6", DateTime.Now)
             {
                 Date = DateTime.Now, Reference = "ref6", Deposit = 300, Withdrawal = 100
             }
         }
     }
         );
     context.SaveChanges();
 }
 public BankAccountRepository()
 {
     try
     {
         var context = new BankAccountContext();
         context.Database.Migrate(); // apply all migrations
     }
     catch (Exception ex)
     {
     }
 }
        /// <summary>
        /// Update the list of phones with the customer Ids.
        /// </summary>
        /// <param name="phones">The phones to be inserted.</param>
        /// <param name="phonesDTO">The phonesDTO to be inserted.</param>
        /// <param name="customersDTO">The customersDTO to be inserted.</param>
        public void UpdateCustomerIds(List <CustomerDTO> customersDTO, List <PhoneNumber> phones, List <PhoneNumberDTO> phonesDTO)
        {
            if (phones == null)
            {
                throw new ArgumentNullException("The phones can not be null.");
            }

            if (phonesDTO == null)
            {
                throw new ArgumentNullException("The phonesDTO can not be null.");
            }

            if (customersDTO == null)
            {
                throw new ArgumentNullException("The customersDTO can not be null.");
            }

            try
            {
                var customers = new List <Customer>();

                using (var dbContext = new BankAccountContext())
                {
                    var repositoryCustomer = new Repositories.RepositoryBaseEF <Customer>(dbContext);

                    customers = repositoryCustomer.Get();
                    if (customers.Count <= 0)
                    {
                        throw new ArgumentNullException("The customers can not be null.");
                    }
                }

                for (int j = 0; j < phonesDTO.Count; j++)
                {
                    for (int i = 0; i < customers.Count; i++)
                    {
                        if (phonesDTO[j].CustomerNo.Equals(customersDTO[i].CustomerNo))
                        {
                            phones[j].CustomerId = customers[i].Id;
                            break;
                        }
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private static void Main(string[] args)
        {
            using (var context = new BankAccountContext())
            {
                IAccountService accountService = new BankAccountService(context);

                accountService.OpenAccount(new User("123", "123"), AccountType.Platinum, out int id);
                Console.WriteLine(accountService.Info(id));
                accountService.Deposite(id, 1000);
                Console.WriteLine(accountService.Info(id));
                accountService.Withdraw(id, 10);
                Console.WriteLine(accountService.Info(id));
                accountService.CloseAccount(id);
                Console.WriteLine(accountService.Info(id));
            }
        }
Example #10
0
        /// <summary>
        /// Validate customer of an account.
        /// </summary>
        public static async Task <bool> CustomerValidation(int accountId, int customerId, string accountNo)
        {
            using (var dbContext = new BankAccountContext())
            {
                var repositoryCustomer = new RepositoryBaseEF <Customer>(dbContext);
                var customer           = await repositoryCustomer.FindById(customerId).ConfigureAwait(false);

                var repositoryAccount = new RepositoryBaseEF <Account>(dbContext);
                if (repositoryAccount.Get().Any(a => a.Id == accountId))
                {
                    return(true);
                }

                var message = string.Format("Customer ID: {0}, You do not allow to withdraw money from Account No.: {1}", customer.CustomerNo, accountNo);
                Console.WriteLine(message);
                return(false);
            }
        }
Example #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              BankAccountContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                dbContext.Database.EnsureCreated();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();
        }
        /// <summary>
        /// Delete all data from the database tables.
        /// </summary>
        public static async Task DeleteData(CancellationToken cancellationToken = default)
        {
            try
            {
                using (var dbContext = new BankAccountContext())
                {
                    var repositoryAccount = new Repositories.RepositoryBaseEF <Account>(dbContext);
                    var accounts          = repositoryAccount.Get();
                    repositoryAccount.DeleteEntities(accounts);
                    await repositoryAccount.SaveAsync().ConfigureAwait(false);

                    var repositoryCustomer = new Repositories.RepositoryBaseEF <Customer>(dbContext);
                    var customers          = repositoryCustomer.Get();
                    repositoryCustomer.DeleteEntities(customers);
                    await repositoryCustomer.SaveAsync().ConfigureAwait(false);

                    var repositoryCustomerAccount = new Repositories.RepositoryBaseEF <CustomerAccount>(dbContext);
                    var customerAccounts          = repositoryCustomerAccount.Get();
                    repositoryCustomerAccount.DeleteEntities(customerAccounts);
                    await repositoryCustomerAccount.SaveAsync().ConfigureAwait(false);

                    var repositoryPhone = new Repositories.RepositoryBaseEF <PhoneNumber>(dbContext);
                    var phones          = repositoryPhone.Get();
                    repositoryPhone.DeleteEntities(phones);
                    await repositoryPhone.SaveAsync().ConfigureAwait(false);

                    var repositoryTransaction = new Repositories.RepositoryBaseEF <Transaction>(dbContext);
                    var transactions          = repositoryTransaction.Get();
                    repositoryTransaction.DeleteEntities(transactions);
                    await repositoryTransaction.SaveAsync().ConfigureAwait(false);
                }
            }
            catch (DbException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Initialize the list of objects and save them into database table and do the transactions process.
        /// </summary>
        public static async Task SaveDataAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                // Initialize the list of objects and save them into database table.
                string filePath     = "\\Data\\customers.json";
                var    customersDTO = IOHelpers.ReadFromFile <Customer, CustomerDTO>(filePath);

                var repositoryCustomer = new RepositoryCustomer();
                var customers          = IOHelpers.EntitiesList <Customer, CustomerDTO>(customersDTO, repositoryCustomer.BusinessToDomainObjectPropertyMap());

                using (var dbContext = new BankAccountContext())
                {
                    var repository = new RepositoryBaseEF <Customer>(dbContext);

                    await repository.CreateEntities(customers).ConfigureAwait(false);

                    await repository.SaveAsync().ConfigureAwait(false);
                }

                filePath = "\\Data\\accounts.json";
                var accountsDTO = IOHelpers.ReadFromFile <Account, AccountDTO>(filePath);

                var repositoryAccount = new RepositoryAccount();
                var accounts          = IOHelpers.EntitiesList <Account, AccountDTO>(accountsDTO, repositoryAccount.BusinessToDomainObjectPropertyMap());

                using (var dbContext = new BankAccountContext())
                {
                    var repository = new RepositoryBaseEF <Account>(dbContext);

                    await repository.CreateEntities(accounts).ConfigureAwait(false);

                    await repository.SaveAsync().ConfigureAwait(false);
                }

                if (accountsDTO.Count > 0)
                {
                    await repositoryCustomer.CreateCustomerAccounts(accountsDTO);
                }

                filePath = "\\Data\\phones.json";
                var phonesDTO = IOHelpers.ReadFromFile <PhoneNumber, PhoneNumberDTO>(filePath);

                var repositoryPhone = new RepositoryPhone();
                var phones          = IOHelpers.EntitiesList <PhoneNumber, PhoneNumberDTO>(phonesDTO, repositoryPhone.BusinessToDomainObjectPropertyMap());

                if (phonesDTO.Count > 0 && customersDTO.Count > 0)
                {
                    repositoryPhone.UpdateCustomerIds(customersDTO, phones, phonesDTO);
                }

                using (var dbContext = new BankAccountContext())
                {
                    var repository = new RepositoryBaseEF <PhoneNumber>(dbContext);

                    await repository.CreateEntities(phones).ConfigureAwait(false);

                    await repository.SaveAsync().ConfigureAwait(false);
                }
            }
            catch (DbException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Update the list of transactions with the customer and account Ids.
        /// </summary>
        /// <param name="transactions">The transactions to be inserted.</param>
        /// <param name="transactionDTOs">The transactionDTOs to be inserted.</param>
        public async Task UpdateIds(List <Transaction> transactions, List <TransactionDTO> transactionDTOs)
        {
            if (transactions == null)
            {
                throw new ArgumentNullException("The transactions can not be null.");
            }

            if (transactionDTOs == null)
            {
                throw new ArgumentNullException("The transactionDTOs can not be null.");
            }

            try
            {
                var customers        = new List <Customer>();
                var accounts         = new List <Account>();
                var customerAccounts = new List <CustomerAccount>();

                using (var dbContext = new BankAccountContext())
                {
                    var repositoryCustomer        = new Repositories.RepositoryBaseEF <Customer>(dbContext);
                    var repositoryAccount         = new Repositories.RepositoryBaseEF <Account>(dbContext);
                    var repositoryCustomerAccount = new Repositories.RepositoryBaseEF <CustomerAccount>(dbContext);

                    customers = await Task.FromResult(repositoryCustomer.Get());

                    accounts         = repositoryAccount.Get();
                    customerAccounts = repositoryCustomerAccount.Get();
                }

                if (accounts.Count <= 0)
                {
                    throw new ArgumentNullException("The accounts can not be null.");
                }

                if (customers.Count <= 0)
                {
                    throw new ArgumentNullException("The customers can not be null.");
                }

                if (customerAccounts.Count <= 0)
                {
                    throw new ArgumentNullException("The customerAccounts can not be null.");
                }

                for (int j = 0; j < transactionDTOs.Count; j++)
                {
                    for (int i = 0; i < customers.Count; i++)
                    {
                        if (transactionDTOs[j].CustomerNo.Equals(customers[i].CustomerNo))
                        {
                            transactions[j].CustomerId = customers[i].Id;
                            transactions[j].AccountId  = -1;
                            if (customers[i].CustomerAccounts != null)
                            {
                                for (int k = 0; k < accounts.Count; k++)
                                {
                                    if (transactionDTOs[j].AccountNo.Equals(accounts[k].AccountNo))
                                    {
                                        transactions[j].AccountId = accounts[k].Id;
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public HomeController(BankAccountContext context)
 {
     _context = context;
 }
 public AccountRepository(BankAccountContext context)
 {
     _context = context;
 }
Example #17
0
        /// <summary>
        /// Read the list of transactions from file and do them.
        /// </summary>
        public static async Task TransactionProcessAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                string filePath        = "\\Data\\transactions.json";
                var    transactionsDTO = IOHelpers.ReadFromFile <Transaction, TransactionDTO>(filePath);

                var repositoryTransaction = new RepositoryTransaction();
                var transactions          = IOHelpers.EntitiesList <Transaction, TransactionDTO>(transactionsDTO, repositoryTransaction.BusinessToDomainObjectPropertyMap());

                await repositoryTransaction.UpdateIds(transactions, transactionsDTO);

                using (var dbContext = new BankAccountContext())
                {
                    var repositoryAccountContext = new RepositoryBaseEF <Account>(dbContext);

                    for (int i = 0; i < transactions.Count; i++)
                    {
                        var transactionDone = false;

                        var account = await repositoryAccountContext.FindById(transactions[i].AccountId);

                        repositoryTransaction = new RepositoryTransaction(account);

                        var message = string.Empty;
                        message = string.Format("Ouput {0}:", (i + 1).ToString());
                        repositoryTransaction.report(message);

                        var validation = true;
                        if (transactions[i].TransactionType == Models.Enums.TransactionTypes.WithdrawCash ||
                            transactions[i].TransactionType == Models.Enums.TransactionTypes.WithdrawTrnasfer)
                        {
                            validation = await Validators.Validations.CustomerValidation(transactions[i].AccountId, transactions[i].CustomerId, transactionsDTO[i].AccountNo);
                        }

                        var accountDestination = new Account();
                        if (validation)
                        {
                            switch (transactions[i].TransactionType)
                            {
                            case Models.Enums.TransactionTypes.DepositCash:
                                repositoryTransaction.DepositCash(transactions[i]);
                                message = string.Format("Account Number: {0} Balance: ${1} CAD", account.AccountNo, account.Balance.ToString());
                                repositoryTransaction.report(message);
                                transactionDone = true;
                                break;

                            case Models.Enums.TransactionTypes.WithdrawCash:
                                message = repositoryTransaction.WithdrawCash(transactions[i]);
                                if (message.Equals(string.Empty))
                                {
                                    message = string.Format("Account Number: {0} Balance: ${1} CAD", account.AccountNo, account.Balance.ToString());
                                    repositoryTransaction.report(message);
                                    transactionDone = true;
                                }
                                else
                                {
                                    repositoryTransaction.report(message);
                                    transactionDone = false;
                                }
                                break;

                            case Models.Enums.TransactionTypes.WithdrawTrnasfer:
                                foreach (Account ac in repositoryAccountContext.Get())
                                {
                                    if (ac.AccountNo.Equals(transactions[i].TransactionAccountNo))
                                    {
                                        accountDestination = ac;
                                        break;
                                    }
                                }
                                message = repositoryTransaction.WithdrawTrnasfer(transactions[i], accountDestination);
                                if (message.Equals(string.Empty))
                                {
                                    message = string.Format("Account Number: {0} Balance: ${1} CAD Account Number: {2} Balance: ${3} CAD",
                                                            account.AccountNo, account.Balance, accountDestination.AccountNo, accountDestination.Balance);
                                    repositoryTransaction.report(message);
                                    transactionDone = true;
                                }
                                else
                                {
                                    repositoryTransaction.report(message);
                                    transactionDone = false;
                                }
                                break;
                            }
                        }

                        if (transactionDone)
                        {
                            var repositoryTransactionContext = new RepositoryBaseEF <Transaction>(dbContext);
                            await repositoryTransactionContext.Create(transactions[i]).ConfigureAwait(false);

                            await repositoryTransactionContext.SaveAsync().ConfigureAwait(false);

                            await repositoryAccountContext.Update(account).ConfigureAwait(false);

                            await repositoryAccountContext.SaveAsync().ConfigureAwait(false);

                            if (accountDestination != null && transactions[i].TransactionType == Models.Enums.TransactionTypes.WithdrawTrnasfer)
                            {
                                await repositoryAccountContext.Update(accountDestination).ConfigureAwait(false);

                                await repositoryAccountContext.SaveAsync().ConfigureAwait(false);
                            }
                        }
                    }
                }
            }
            catch (DbException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public TransactionController(BankAccountContext context)
 {
     _context = context;
 }
Example #19
0
        /// <summary>
        /// Read the list of objects from a file.
        /// </summary>
        public static async Task <Dictionary <string, decimal> > Transaction(string filePath)
        {
            var transactionsDTO = IOHelpers.ReadFromFile <Transaction, TransactionDTO>(filePath, true);

            var repositoryTransaction = new RepositoryTransaction();
            var transactions          = IOHelpers.EntitiesList <Transaction, TransactionDTO>(transactionsDTO, repositoryTransaction.BusinessToDomainObjectPropertyMap());

            await repositoryTransaction.UpdateIds(transactions, transactionsDTO);

            Dictionary <string, decimal> balances = new Dictionary <string, decimal>();

            using (var dbContext = new BankAccountContext())
            {
                var repositoryAccountContext = new RepositoryBaseEF <Account>(dbContext);

                for (int i = 0; i < transactions.Count; i++)
                {
                    var transactionDone = false;

                    var account = await repositoryAccountContext.FindById(transactions[i].AccountId);

                    repositoryTransaction = new RepositoryTransaction(account);

                    var message = string.Empty;
                    message = string.Format("Ouput {0}:", (i + 1).ToString());
                    repositoryTransaction.report(message);

                    var validation = true;
                    if (transactions[i].TransactionType == TransactionTypes.WithdrawCash ||
                        transactions[i].TransactionType == TransactionTypes.WithdrawTrnasfer)
                    {
                        validation = await Validators.Validations.CustomerValidation(transactions[i].AccountId, transactions[i].CustomerId, transactionsDTO[i].AccountNo);
                    }

                    var accountDestination = new Account();
                    if (validation)
                    {
                        switch (transactions[i].TransactionType)
                        {
                        case TransactionTypes.DepositCash:
                            repositoryTransaction.DepositCash(transactions[i]);
                            message = string.Format("Account Number: {0} Balance: ${1} CAD", account.AccountNo, account.Balance.ToString());
                            repositoryTransaction.report(message);
                            transactionDone = true;
                            break;

                        case TransactionTypes.WithdrawCash:
                            message = repositoryTransaction.WithdrawCash(transactions[i]);
                            if (message.Equals(string.Empty))
                            {
                                message = string.Format("Account Number: {0} Balance: ${1} CAD", account.AccountNo, account.Balance.ToString());
                                repositoryTransaction.report(message);
                                transactionDone = true;
                            }
                            else
                            {
                                repositoryTransaction.report(message);
                                transactionDone = false;
                            }
                            break;

                        case TransactionTypes.WithdrawTrnasfer:
                            foreach (Account ac in repositoryAccountContext.Get())
                            {
                                if (ac.AccountNo.Equals(transactions[i].TransactionAccountNo))
                                {
                                    accountDestination = ac;
                                    break;
                                }
                            }
                            message = repositoryTransaction.WithdrawTrnasfer(transactions[i], accountDestination);
                            if (message.Equals(string.Empty))
                            {
                                message = string.Format("Account Number: {0} Balance: ${1} CAD Account Number: {2} Balance: ${3} CAD",
                                                        account.AccountNo, account.Balance, accountDestination.AccountNo, accountDestination.Balance);
                                repositoryTransaction.report(message);
                                transactionDone = true;
                            }
                            else
                            {
                                repositoryTransaction.report(message);
                                transactionDone = false;
                            }
                            break;
                        }
                    }

                    if (transactionDone)
                    {
                        var repositoryTransactionContext = new RepositoryBaseEF <Transaction>(dbContext);
                        await repositoryTransactionContext.Create(transactions[i]).ConfigureAwait(false);

                        await repositoryTransactionContext.SaveAsync().ConfigureAwait(false);

                        await repositoryAccountContext.Update(account).ConfigureAwait(false);

                        await repositoryAccountContext.SaveAsync().ConfigureAwait(false);

                        if (accountDestination != null && transactions[i].TransactionType == TransactionTypes.WithdrawTrnasfer)
                        {
                            await repositoryAccountContext.Update(accountDestination).ConfigureAwait(false);

                            await repositoryAccountContext.SaveAsync().ConfigureAwait(false);
                        }
                    }

                    if (account != null && account.AccountNo != null && account.AccountNo != string.Empty)
                    {
                        var key = account.AccountNo;
                        if (balances.ContainsKey(key))
                        {
                            balances[key] = account.Balance;
                        }
                        else
                        {
                            balances.Add(key, account.Balance);
                        }
                    }

                    if (accountDestination != null && accountDestination.AccountNo != null && accountDestination.AccountNo != string.Empty)
                    {
                        var key = accountDestination.AccountNo;
                        if (balances.ContainsKey(key))
                        {
                            balances[key] = accountDestination.Balance;
                        }
                        else
                        {
                            balances.Add(key, accountDestination.Balance);
                        }
                    }
                }
            }
            return(balances);
        }
 public TransactionRepository(BankAccountContext context)
 {
     _context = context;
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BankAccountService"/> class.
 /// </summary>
 public BankAccountService(BankAccountContext context)
 {
     this.bankAccounts = new DbStorage(context);
 }
Example #22
0
 public UsersController(BankAccountContext connect)
 {
     _dbConnector = connect;
 }
Example #23
0
        /// <summary>
        /// Insert a list of customrAccounts in the database table.
        /// </summary>
        /// <param name="accountsDTO">The accountsDTO to be inserted.</param>
        public async Task CreateCustomerAccounts(List <AccountDTO> accountsDTO)
        {
            if (accountsDTO == null)
            {
                throw new ArgumentNullException("The accountsDTO can not be null.");
            }

            var accounts  = new List <Account>();
            var customers = new List <Customer>();

            using (var dbContext = new BankAccountContext())
            {
                var repositoryAccount  = new Repositories.RepositoryBaseEF <Account>(dbContext);
                var repositoryCustomer = new Repositories.RepositoryBaseEF <Customer>(dbContext);

                accounts = repositoryAccount.Get();
                if (accounts.Count <= 0)
                {
                    throw new ArgumentNullException("The accounts can not be null.");
                }

                customers = repositoryCustomer.Get();
                if (customers.Count <= 0)
                {
                    throw new ArgumentNullException("The customers can not be null.");
                }
            }

            try
            {
                using (var dbContext = new BankAccountContext())
                {
                    var repository = new RepositoryBaseEF <CustomerAccount>(dbContext);

                    var customerAccounts = new List <CustomerAccount>();

                    for (int j = 0; j < accountsDTO.Count; j++)
                    {
                        for (int i = 0; i < customers.Count; i++)
                        {
                            if (accountsDTO[j].CustomerNo.Equals(customers[i].CustomerNo))
                            {
                                var customerAccount = new CustomerAccount();
                                customerAccount.CustomerId  = customers[i].Id;
                                customerAccount.AccountId   = accounts[j].Id;
                                customerAccount.CreatedDate = DateTime.Now.ToString();
                                customerAccount.CreatedBy   = "Aziz Azimi";
                                customerAccounts.Add(customerAccount);
                                break;
                            }
                        }
                    }

                    try
                    {
                        await repository.CreateEntities(customerAccounts);

                        await repository.SaveAsync();
                    }
                    catch (DbException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #24
0
 public DbStorage(BankAccountContext context)
 {
     this.context = context;
 }
Example #25
0
 public BankRepository(BankAccountContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #26
0
 public BankAccountRepository(BankAccountContext context) => _context = context;
Example #27
0
 public UsersController(BankAccountContext context)
 {
     _context = context;
 }
 public ActionsController(BankAccountContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RepositoryBase{Task}"/> class.
 /// </summary>
 public RepositoryBaseEF(BankAccountContext context)
 {
     _context = context;
 }
 public BankStatementRepository(BankAccountContext context)
 {
     _context = context;
 }
Example #31
0
 public BankAccountEFRepository(string connectionString)
 {
     _bankAccountStorage = new BankAccountContext(connectionString);
 }