private static async Task <List <PostingLineModel> > OnReadAsync(AccountingModel accountingModel, IReadOnlyCollection <PostingLineModel> postingLineModelCollection, AccountModelHandler accountModelHandler, BudgetAccountModelHandler budgetAccountModelHandler, ContactAccountModelHandler contactAccountModelHandler, PostingLineModelHandler postingLineModelHandler) { NullGuard.NotNull(accountingModel, nameof(accountingModel)); if (postingLineModelCollection == null || postingLineModelHandler == null) { return(accountingModel.PostingLines); } foreach (AccountModel accountModel in accountingModel.Accounts ?? new List <AccountModel>(0)) { if (accountModel.PostingLines == null) { accountModel.ExtractPostingLines(postingLineModelCollection); } accountModel.PostingLines = (await postingLineModelHandler.ReadAsync(accountModel.PostingLines)).ToList(); if (accountModel.PostingLines.Any() == false && accountModelHandler != null) { accountModel.Deletable = await accountModelHandler.IsDeletableAsync(accountModel); } } foreach (BudgetAccountModel budgetAccountModel in accountingModel.BudgetAccounts ?? new List <BudgetAccountModel>(0)) { if (budgetAccountModel.PostingLines == null) { budgetAccountModel.ExtractPostingLines(postingLineModelCollection); } budgetAccountModel.PostingLines = (await postingLineModelHandler.ReadAsync(budgetAccountModel.PostingLines)).ToList(); if (budgetAccountModel.PostingLines.Any() == false && budgetAccountModelHandler != null) { budgetAccountModel.Deletable = await budgetAccountModelHandler.IsDeletableAsync(budgetAccountModel); } } foreach (ContactAccountModel contactAccountModel in accountingModel.ContactAccounts ?? new List <ContactAccountModel>(0)) { if (contactAccountModel.PostingLines == null) { contactAccountModel.ExtractPostingLines(postingLineModelCollection); } contactAccountModel.PostingLines = (await postingLineModelHandler.ReadAsync(contactAccountModel.PostingLines)).ToList(); if (contactAccountModel.PostingLines.Any() == false && contactAccountModelHandler != null) { contactAccountModel.Deletable = await contactAccountModelHandler.IsDeletableAsync(contactAccountModel); } } if (accountingModel.PostingLines == null) { accountingModel.ExtractPostingLines(postingLineModelCollection); } return((await postingLineModelHandler.ReadAsync(accountingModel.PostingLines)).ToList()); }
private async Task <List <PostingLineModel> > OnReadAsync(TAccountModel accountModel, IReadOnlyCollection <PostingLineModel> postingLineModelCollection, PostingLineModelHandler postingLineModelHandler) { NullGuard.NotNull(accountModel, nameof(accountModel)); if (postingLineModelCollection == null || postingLineModelHandler == null) { return(accountModel.PostingLines); } if (accountModel.PostingLines == null) { ExtractPostingLines(accountModel, postingLineModelCollection); } return((await postingLineModelHandler.ReadAsync(accountModel.PostingLines)).ToList()); }