Beispiel #1
0
        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 <ContactAccountModel> OnReadAsync(PostingLineModel postingLineModel, DateTime statusDate, IReadOnlyCollection <ContactAccountModel> contactAccountModelCollection)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel));

            if (contactAccountModelCollection == null || postingLineModel.ContactAccount != null)
            {
                return(await OnReadAsync(postingLineModel.ContactAccount, statusDate, contactAccountModel => _contactAccountModelHandler.IsDeletableAsync(contactAccountModel)));
            }

            if (postingLineModel.ContactAccountIdentifier == null)
            {
                return(null);
            }

            return(await OnReadAsync(contactAccountModelCollection.Single(m => m.ContactAccountIdentifier == postingLineModel.ContactAccountIdentifier.Value), statusDate, contactAccountModel => _contactAccountModelHandler.IsDeletableAsync(contactAccountModel)));
        }