internal static IAccounting ToDomain(this AccountingModel accountingModel, MapperCache mapperCache, IConverter accountingModelConverter, IConverter commonModelConverter) { NullGuard.NotNull(accountingModel, nameof(accountingModel)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)) .NotNull(commonModelConverter, nameof(commonModelConverter)); lock (mapperCache.SyncRoot) { if (mapperCache.AccountingDictionary.TryGetValue(accountingModel.AccountingIdentifier, out IAccounting accounting)) { return(accounting); } ILetterHead letterHead = commonModelConverter.Convert <LetterHeadModel, ILetterHead>(accountingModel.LetterHead); accounting = new Domain.Accounting.Accounting(accountingModel.AccountingIdentifier, accountingModel.Name, letterHead, accountingModel.BalanceBelowZero, accountingModel.BackDating); accounting.AddAuditInformation(accountingModel.CreatedUtcDateTime, accountingModel.CreatedByIdentifier, accountingModel.ModifiedUtcDateTime, accountingModel.ModifiedByIdentifier); accounting.SetDeletable(accountingModel.Deletable); mapperCache.AccountingDictionary.Add(accounting.Number, accounting); if (accountingModel.Accounts != null) { accounting.AccountCollection.Add(accountingModel.Accounts .Where(accountModel => accountModel.Convertible()) .Select(accountModel => accountModel.ToDomain(accounting, mapperCache, accountingModelConverter)) .Where(account => accounting.AccountCollection.Contains(account) == false) .ToArray()); } if (accountingModel.BudgetAccounts != null) { accounting.BudgetAccountCollection.Add(accountingModel.BudgetAccounts .Where(budgetAccountModel => budgetAccountModel.Convertible()) .Select(budgetAccountModel => budgetAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter)) .Where(budgetAccount => accounting.BudgetAccountCollection.Contains(budgetAccount) == false) .ToArray()); } if (accountingModel.ContactAccounts != null) { accounting.ContactAccountCollection.Add(accountingModel.ContactAccounts .Where(contactAccountModel => contactAccountModel.Convertible()) .Select(contactAccountModel => contactAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter)) .Where(contactAccount => accounting.ContactAccountCollection.Contains(contactAccount) == false) .ToArray()); } return(accounting); } }
internal static IAccount ToDomain(this AccountModel accountModel, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accountModel, nameof(accountModel)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IAccounting accounting = accountingModelConverter.Convert <AccountingModel, IAccounting>(accountModel.Accounting); return(accountModel.ToDomain(accounting, mapperCache, accountingModelConverter)); } }
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); } }
private static IContactAccount ResolveContactAccount(ContactAccountModel contactAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); if (contactAccountModel == null) { return(null); } IContactAccount contactAccount = contactAccountModel.Resolve(mapperCache.ContactAccountDictionary) ?? contactAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter); if (accounting.ContactAccountCollection.Contains(contactAccount) == false) { accounting.ContactAccountCollection.Add(contactAccount); } return(contactAccount); }
private static IBudgetAccount ResolveBudgetAccount(BudgetAccountModel budgetAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); if (budgetAccountModel == null) { return(null); } IBudgetAccount budgetAccount = budgetAccountModel.Resolve(mapperCache.BudgetAccountDictionary) ?? budgetAccountModel.ToDomain(accounting, mapperCache, accountingModelConverter); if (accounting.BudgetAccountCollection.Contains(budgetAccount) == false) { accounting.BudgetAccountCollection.Add(budgetAccount); } return(budgetAccount); }
private static IAccount ResolveAccount(AccountModel accountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accountModel, nameof(accountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); IAccount account = accountModel.Resolve(mapperCache.AccountDictionary) ?? accountModel.ToDomain(accounting, mapperCache, accountingModelConverter); if (accounting.AccountCollection.Contains(account) == false) { accounting.AccountCollection.Add(account); } return(account); }
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 IAccount ToDomain(this AccountModel accountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(accountModel, nameof(accountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IAccount account = accountModel.Resolve(mapperCache.AccountDictionary); if (account != null) { return(account); } IAccountGroup accountGroup = accountingModelConverter.Convert <AccountGroupModel, IAccountGroup>(accountModel.AccountGroup); account = new Account(accounting, accountModel.AccountNumber, accountModel.BasicAccount.AccountName, accountGroup) { Description = accountModel.BasicAccount.Description, Note = accountModel.BasicAccount.Note }; accountModel.CopyAuditInformationTo(account); account.SetDeletable(accountModel.Deletable); mapperCache.AccountDictionary.Add(accountModel.AccountIdentifier, account); accounting.AccountCollection.Add(account); if (accountModel.CreditInfos != null) { account.CreditInfoCollection.Populate(account, accountModel.CreditInfos .Where(creditInfoModel => creditInfoModel.Convertible() && (creditInfoModel.YearMonth.Year < accountModel.StatusDateForInfos.Year || creditInfoModel.YearMonth.Year == accountModel.StatusDateForInfos.Year && creditInfoModel.YearMonth.Month <= accountModel.StatusDateForInfos.Month)) .Select(creditInfoModel => creditInfoModel.ToDomain(account)) .ToArray(), accountModel.StatusDate, accountModel.StatusDateForInfos); } if (accountModel.PostingLines != null) { account.PostingLineCollection.Add(accountModel.PostingLines .Where(postingLineModel => postingLineModel.Convertible() && postingLineModel.PostingDate >= accountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < accountModel.GetToDateForPostingLines(1)) .Select(postingLineModel => postingLineModel.ToDomain(accounting, account, mapperCache, accountingModelConverter)) .Where(postingLine => account.PostingLineCollection.Contains(postingLine) == false) .ToArray()); } return(account); } }
internal static IContactAccount ToDomain(this ContactAccountModel contactAccountModel, IAccounting accounting, MapperCache mapperCache, IConverter accountingModelConverter) { NullGuard.NotNull(contactAccountModel, nameof(contactAccountModel)) .NotNull(accounting, nameof(accounting)) .NotNull(mapperCache, nameof(mapperCache)) .NotNull(accountingModelConverter, nameof(accountingModelConverter)); lock (mapperCache.SyncRoot) { IContactAccount contactAccount = contactAccountModel.Resolve(mapperCache.ContactAccountDictionary); if (contactAccount != null) { return(contactAccount); } IPaymentTerm paymentTerm = accountingModelConverter.Convert <PaymentTermModel, IPaymentTerm>(contactAccountModel.PaymentTerm); contactAccount = new ContactAccount(accounting, contactAccountModel.AccountNumber, contactAccountModel.BasicAccount.AccountName, paymentTerm) { Description = contactAccountModel.BasicAccount.Description, Note = contactAccountModel.BasicAccount.Note, MailAddress = contactAccountModel.MailAddress, PrimaryPhone = contactAccountModel.PrimaryPhone, SecondaryPhone = contactAccountModel.SecondaryPhone }; contactAccountModel.CopyAuditInformationTo(contactAccount); contactAccount.SetDeletable(contactAccountModel.Deletable); mapperCache.ContactAccountDictionary.Add(contactAccountModel.ContactAccountIdentifier, contactAccount); accounting.ContactAccountCollection.Add(contactAccount); contactAccount.ContactInfoCollection.Populate(contactAccount, contactAccountModel.StatusDate, contactAccountModel.StatusDateForInfos); if (contactAccountModel.PostingLines != null) { contactAccount.PostingLineCollection.Add(contactAccountModel.PostingLines .Where(postingLineModel => postingLineModel.Convertible() && postingLineModel.PostingDate >= contactAccountModel.GetFromDateForPostingLines() && postingLineModel.PostingDate < contactAccountModel.GetToDateForPostingLines(1)) .Select(postingLineModel => postingLineModel.ToDomain(accounting, contactAccount, mapperCache, accountingModelConverter)) .Where(postingLine => contactAccount.PostingLineCollection.Contains(postingLine) == false) .ToArray()); } return(contactAccount); } }