Esempio n. 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 <AccountModel> OnReadAsync(PostingLineModel postingLineModel, DateTime statusDate, IReadOnlyCollection <AccountModel> accountModelCollection)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel));

            if (accountModelCollection == null || postingLineModel.Account != null)
            {
                return(await OnReadAsync(postingLineModel.Account, statusDate, accountModel => _accountModelHandler.IsDeletableAsync(accountModel)));
            }

            return(await OnReadAsync(accountModelCollection.Single(m => m.AccountIdentifier == postingLineModel.AccountIdentifier), statusDate, accountModel => _accountModelHandler.IsDeletableAsync(accountModel)));
        }