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 <BudgetAccountModel> OnReadAsync(PostingLineModel postingLineModel, DateTime statusDate, IReadOnlyCollection <BudgetAccountModel> budgetAccountModelCollection) { NullGuard.NotNull(postingLineModel, nameof(postingLineModel)); if (budgetAccountModelCollection == null || postingLineModel.BudgetAccount != null) { return(await OnReadAsync(postingLineModel.BudgetAccount, statusDate, budgetAccountModel => _budgetAccountModelHandler.IsDeletableAsync(budgetAccountModel))); } if (postingLineModel.BudgetAccountIdentifier == null) { return(null); } return(await OnReadAsync(budgetAccountModelCollection.Single(m => m.BudgetAccountIdentifier == postingLineModel.BudgetAccountIdentifier.Value), statusDate, budgetAccountModel => _budgetAccountModelHandler.IsDeletableAsync(budgetAccountModel))); }