//Record the state of all accounts if the month has changed public async static Task<bool> RecordBalance(IBalanceReport balanceRepo, IAccountRepository accountRepo) { //created a variable to keep async bool returns, set it to false just in case the code doesnt work, will return false bool success = false; //I record onyl Crdit and Debit account balances because only their balances matter. var accounts = await accountRepo.GetAccountByTwoTypes(AccountType.Credit, AccountType.Debit); //Because the record is happening in the new month any first day the app is accessed, but //the report needs to be for the end of the last month. So the date is last months date. var lastMonthsDate = DateTime.Now.AddMonths(-1); foreach (var acc in accounts) { var balanceReport = new BalanceReport { AccountId = acc.Id, Date = lastMonthsDate, Value = acc.Value }; success = await balanceRepo.Create(balanceReport); } return success; }