internal static void ExtractPostingLines(this BudgetAccountModel budgetAccountModel, IReadOnlyCollection <PostingLineModel> postingLineModelCollection) { NullGuard.NotNull(budgetAccountModel, nameof(budgetAccountModel)) .NotNull(postingLineModelCollection, nameof(postingLineModelCollection)); budgetAccountModel.PostingLines = postingLineModelCollection .Where(postingLineModel => postingLineModel.BudgetAccountIdentifier != null && postingLineModel.BudgetAccountIdentifier.Value == budgetAccountModel.BudgetAccountIdentifier && postingLineModel.PostingDate >= budgetAccountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < budgetAccountModel.GetToDateForPostingLines(1)) .ToList(); }
internal static IBudgetAccount ToDomain(this BudgetAccountModel budgetAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(budgetAccountModel, nameof(budgetAccountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IBudgetAccount budgetAccount = budgetAccountModel.Resolve(mapperCache.BudgetAccountDictionary); if (budgetAccount != null) { return(budgetAccount); } IBudgetAccountGroup budgetAccountGroup = accountingModelConverter.Convert <BudgetAccountGroupModel, IBudgetAccountGroup>(budgetAccountModel.BudgetAccountGroup); budgetAccount = new BudgetAccount(accounting, budgetAccountModel.AccountNumber, budgetAccountModel.BasicAccount.AccountName, budgetAccountGroup) { Description = budgetAccountModel.BasicAccount.Description, Note = budgetAccountModel.BasicAccount.Note }; budgetAccountModel.CopyAuditInformationTo(budgetAccount); budgetAccount.SetDeletable(budgetAccountModel.Deletable); mapperCache.BudgetAccountDictionary.Add(budgetAccountModel.BudgetAccountIdentifier, budgetAccount); accounting.BudgetAccountCollection.Add(budgetAccount); if (budgetAccountModel.BudgetInfos != null) { budgetAccount.BudgetInfoCollection.Populate(budgetAccount, budgetAccountModel.BudgetInfos .Where(budgetInfoModel => budgetInfoModel.Convertible() && (budgetInfoModel.YearMonth.Year < budgetAccountModel.StatusDateForInfos.Year || budgetInfoModel.YearMonth.Year == budgetAccountModel.StatusDateForInfos.Year && budgetInfoModel.YearMonth.Month <= budgetAccountModel.StatusDateForInfos.Month)) .Select(budgetInfoModel => budgetInfoModel.ToDomain(budgetAccount)) .ToArray(), budgetAccountModel.StatusDate, budgetAccountModel.StatusDateForInfos); } if (budgetAccountModel.PostingLines != null) { budgetAccount.PostingLineCollection.Add(budgetAccountModel.PostingLines .Where(postingLineModel => postingLineModel.Convertible() && postingLineModel.PostingDate >= budgetAccountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < budgetAccountModel.GetToDateForPostingLines(1)) .Select(postingLineModel => postingLineModel.ToDomain(accounting, budgetAccount, mapperCache, accountingModelConverter)) .Where(postingLine => budgetAccount.PostingLineCollection.Contains(postingLine) == false) .ToArray()); } return(budgetAccount); } }