public async Task <Customer> Add(Customer customer) { int CustomerMainCurrencyId = customer.MainCurrencyId; var listOfCustomerAccounts = customer.Accounts; var countOfAccountsInDb = await _context.Accounts.CountAsync(); if (countOfAccountsInDb != 0) { maxOFAccountNumber = await _context.Accounts .MaxAsync(a => a.AccountNumber); } foreach (Account account in listOfCustomerAccounts) { account.BalanceWithAccountCurrency = await BalanceWithAccountCurrency(account); account.BalanceWithCustomerMainCurrency = await BalanceWithCustomerMainCurrency(CustomerMainCurrencyId, account); countOfAccountsInDb = await _context.Accounts.CountAsync(); if (countOfAccountsInDb != 0) { account.AccountNumber = maxOFAccountNumber + StaticCounter.AddOne(); } else if (StaticCounter.count >= 0 && countOfAccountsInDb == 0) { account.AccountNumber = StaticCounter.AddOne(); } } _context.Add(customer); await _context.SaveChangesAsync(); return(customer); }