public PostingLineModelHandler(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime fromDate, DateTime toDate, bool includeCreditInformation, bool includeBudgetInformation, int?numberOfPostingLines = null, bool applyingPostingLines = false) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _eventPublisher = eventPublisher; _fromDate = fromDate.Date; _toDate = toDate.Date; _includeCreditInformation = includeCreditInformation; _includeBudgetInformation = includeBudgetInformation; _numberOfPostingLines = numberOfPostingLines; _applyingPostingLines = applyingPostingLines; _accountingModelHandler = new AccountingModelHandler(dbContext, ModelConverter, _eventPublisher, _toDate, false, false); _accountModelHandler = new AccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, _includeCreditInformation, false, true); _budgetAccountModelHandler = new BudgetAccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, _includeBudgetInformation, false, true); _contactAccountModelHandler = new ContactAccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, false, true); _eventPublisher.AddSubscriber(this); }
public AccountingModelHandler(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime statusDate, bool includeAccounts, bool includePostingLines) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _eventPublisher = eventPublisher; _statusDate = statusDate.Date; _includeAccounts = includeAccounts; _includePostingLines = includePostingLines; if (_includeAccounts) { _accountModelHandler = new AccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, true, false); _budgetAccountModelHandler = new BudgetAccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, true, false); _contactAccountModelHandler = new ContactAccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, false); } if (_includePostingLines) { _postingLineModelHandler = new PostingLineModelHandler(dbContext, modelConverter, _eventPublisher, DateTime.MinValue, _statusDate, false, false); } _eventPublisher.AddSubscriber(this); }
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 static async Task <List <ContactAccountModel> > OnReadAsync(AccountingModel accountingModel, IReadOnlyCollection <ContactAccountModel> contactAccountModelCollection, ContactAccountModelHandler contactAccountModelHandler) { NullGuard.NotNull(accountingModel, nameof(accountingModel)); if (contactAccountModelCollection == null || contactAccountModelHandler == null) { return(accountingModel.ContactAccounts); } if (accountingModel.ContactAccounts == null) { accountingModel.ExtractContactAccounts(contactAccountModelCollection); } return((await contactAccountModelHandler.ReadAsync(accountingModel.ContactAccounts)).ToList()); }