internal static bool Convertible(this PostingLineModel postingLineModel)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel));

            return(postingLineModel.Accounting != null &&
                   postingLineModel.Accounting.Convertible() &&
                   postingLineModel.Account != null &&
                   postingLineModel.Account.Convertible() &&
                   (postingLineModel.BudgetAccount == null || postingLineModel.BudgetAccount.Convertible()) &&
                   (postingLineModel.ContactAccount == null || postingLineModel.ContactAccount.Convertible()));
        }
        internal static IPostingLine ToDomain(this PostingLineModel postingLineModel, IAccount account, IBudgetAccount budgetAccount, IContactAccount contactAccount, MapperCache mapperCache)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel))
            .NotNull(account, nameof(account))
            .NotNull(mapperCache, nameof(mapperCache));

            Guid postingLineIdentification = Guid.Parse(postingLineModel.PostingLineIdentification);

            lock (mapperCache.SyncRoot)
            {
                if (mapperCache.PostingLineDictionary.TryGetValue(postingLineIdentification, out IPostingLine postingLine))
                {
                    return(postingLine);
                }

                ICreditInfo       creditInfo = account.CreditInfoCollection.Find(postingLineModel.PostingDate);
                ICreditInfoValues accountValuesAtPostingDate = new CreditInfoValues(creditInfo?.Credit ?? 0M, postingLineModel.PostingValueForAccount);

                IBudgetInfoValues budgetAccountValuesAtPostingDate = null;
                if (budgetAccount != null)
                {
                    IBudgetInfo budgetInfo = budgetAccount.BudgetInfoCollection.Find(postingLineModel.PostingDate);
                    budgetAccountValuesAtPostingDate = new BudgetInfoValues(budgetInfo?.Budget ?? 0M, postingLineModel.PostingValueForBudgetAccount ?? 0M);
                }

                IContactInfoValues contactAccountValuesAtPostingDate = null;
                if (contactAccount != null)
                {
                    contactAccountValuesAtPostingDate = new ContactInfoValues(postingLineModel.PostingValueForContactAccount ?? 0M);
                }

                postingLine = new PostingLine(postingLineIdentification, postingLineModel.PostingDate, postingLineModel.Reference, account, postingLineModel.Details, budgetAccount, postingLineModel.Debit ?? 0M, postingLineModel.Credit ?? 0M, contactAccount, postingLineModel.PostingLineIdentifier, accountValuesAtPostingDate, budgetAccountValuesAtPostingDate, contactAccountValuesAtPostingDate);
                postingLine.AddAuditInformation(postingLineModel.CreatedUtcDateTime, postingLineModel.CreatedByIdentifier, postingLineModel.ModifiedUtcDateTime, postingLineModel.ModifiedByIdentifier);

                mapperCache.PostingLineDictionary.Add(postingLineIdentification, postingLine);

                if (account.PostingLineCollection.Contains(postingLine) == false)
                {
                    account.PostingLineCollection.Add(postingLine);
                }

                if (budgetAccount != null && budgetAccount.PostingLineCollection.Contains(postingLine) == false)
                {
                    budgetAccount.PostingLineCollection.Add(postingLine);
                }

                if (contactAccount != null && contactAccount.PostingLineCollection.Contains(postingLine) == false)
                {
                    contactAccount.PostingLineCollection.Add(postingLine);
                }

                return(postingLine);
            }
        }
        internal static IPostingLine ToDomain(this PostingLineModel postingLineModel, IAccounting accounting, IContactAccount contactAccount, MapperCache mapperCache, IConverter accountingModelConverter)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel))
            .NotNull(accounting, nameof(accounting))
            .NotNull(contactAccount, nameof(contactAccount))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter));

            IAccount       account       = ResolveAccount(postingLineModel.Account, accounting, mapperCache, accountingModelConverter);
            IBudgetAccount budgetAccount = ResolveBudgetAccount(postingLineModel.BudgetAccount, accounting, mapperCache, accountingModelConverter);

            return(postingLineModel.ToDomain(account, budgetAccount, contactAccount, mapperCache));
        }
        internal static IPostingLine ToDomain(this PostingLineModel postingLineModel, MapperCache mapperCache, IConverter accountingModelConverter)
        {
            NullGuard.NotNull(postingLineModel, nameof(postingLineModel))
            .NotNull(mapperCache, nameof(mapperCache))
            .NotNull(accountingModelConverter, nameof(accountingModelConverter));

            lock (mapperCache.SyncRoot)
            {
                IAccounting accounting = accountingModelConverter.Convert <AccountingModel, IAccounting>(postingLineModel.Accounting);

                return(postingLineModel.ToDomain(accounting, mapperCache, accountingModelConverter));
            }
        }