public MyAccountsDetailVm Convert(Account source, MyAccountsDetailVm destination, ResolutionContext context) { if (source == null) { return(null); } if (destination == null) { destination = new MyAccountsDetailVm(); } destination.PlanDescription = _mapperHelper.DerivePlanDescription(source); destination.DiscountAvailableLinkTextOptional = _mapperHelper.DeriveDiscountDescription(source); if (!string.IsNullOrEmpty(source.AccountMessage)) { destination.AccountMessage = source.AccountMessage; } destination.ArrearsMessage = _mapperHelper.DeriveArrearsDetail(source.PaymentPlanArrearsAmount, source.PaymentPlanIsAutomated); destination.RecentTransactions = _mapper.Map <List <Transaction>, List <TransactionVm> >(source.RecentTransactions); destination.OriginalCompanyText = source.OriginalCompany; destination.AccountReferenceText = source.AccountReference; destination.OutstandingBalanceText = source.OutstandingBalance.ToString("C", CultureInfo.CurrentCulture); destination.AccountStatusText = source.AccountStatus; destination.NextPlanPaymentDate = source.NextPlanPaymentDate; destination.ClientReference = source.ClientReference; destination.AddedSinceLastLogin = source.AddedSinceLastLogin; destination.HasArrangement = source.HasArrangement; destination.PlanPendingTransfer = source.PlanPendingTransfer; destination.PlanTransferredFrom = source.PlanTransferredFrom; destination.NeverAllowPlanTransfer = source.NeverAllowPlanTransfer; destination.PlanTransferOptOutNumber = _portalSettings.PlanTransferOptOutNumber; if (!string.IsNullOrEmpty(destination.PlanTransferredFrom)) { destination.PlanTransferredFromAccounts = destination.PlanTransferredFrom.Split(',').ToList(); destination.PlanTransferredFromAccountsFormatted = _mapperHelper.DerivePlanTransferredFromAccountsFormatted(destination.PlanTransferredFromAccounts); } if (source.DiscountedBalance != null) { destination.DiscountedBalanceTextOptional = source.DiscountedBalance.Value.ToString("C", CultureInfo.CurrentCulture); } if (source.AccountStatusIsWithSolicitors) { destination.SolicitorsRedirectLink = _portalSettings.SolicitorsRedirectUrl; } destination.IsPaymentButtonAvailable = source.CanMakePayment; destination.CanAmendPlan = source.CanAmendPlan; if (source.AccountStatusIsViewOnly) { destination.DiscountAvailableLinkTextOptional = null; } if (source.AccountStatusIsClosed) { destination.ArrearsMessage = null; destination.DiscountAvailableLinkTextOptional = null; destination.IsPaymentButtonAvailable = false; destination.CanAmendPlan = false; } destination.DirectDebitInFlight = source.DirectDebitInFlight; destination.AccountWithSolicitors = source.AccountStatusIsWithSolicitors; destination.PlanMessage = (source.PlanMessages != null && source.PlanMessages.Length > 0) ? source.PlanMessages[0] : string.Empty; return(destination); }
public MyAccountsVm Convert(CustomerSummary source, MyAccountsVm destination, ResolutionContext context) { if (source == null || source.Accounts == null || source.SurrogateKeysByLowellReference == null) { return(null); } if (destination == null) { destination = new MyAccountsVm(); } Guid?lowellFinancialAccountSurrogateKey = null; destination.Accounts = new List <AccountSummaryVm>(); foreach (AccountSummary account in source.Accounts) { AccountSummaryVm accountVm = new AccountSummaryVm(); Guid lowellReferenceSurrogateKey = source.SurrogateKeysByLowellReference[account.AccountReference]; accountVm.PlanDescription = _mapperHelper.DerivePlanDescription(account); accountVm.DiscountAvailableLinkTextOptional = _mapperHelper.DeriveDiscountDescription(account); if (account.CanManageAccount) { accountVm.DetailsLinkText = "Manage account"; } else { accountVm.DetailsLinkText = "View"; } accountVm.ArrearsMessage = _mapperHelper.DeriveArrearsSummary(account.PaymentPlanArrearsAmount); if (!account.AccountStatusIsWithSolicitors && lowellFinancialAccountSurrogateKey == null) { lowellFinancialAccountSurrogateKey = lowellReferenceSurrogateKey; } accountVm.Class = "info-box"; if (account.AccountStatusIsClosed) { accountVm.Class = "info-box--disabled"; } if (accountVm.ArrearsMessage != null) { accountVm.Class = "info-box--warning"; accountVm.ShowWarningSymbol = true; } accountVm.AccountStatusIsWithSolicitors = account.AccountStatusIsWithSolicitors; accountVm.LowellReferenceSurrogateKey = lowellReferenceSurrogateKey; accountVm.OriginalCompanyText = account.OriginalCompany; accountVm.AccountReferenceText = account.AccountReference; accountVm.OutstandingBalanceText = account.OutstandingBalance.ToString("C", CultureInfo.CurrentCulture); accountVm.AccountStatusText = account.AccountStatus; accountVm.NextPlanPaymentDate = account.NextPlanPaymentDate; accountVm.ClientReference = account.ClientReference; accountVm.AddedSinceLastLogin = account.AddedSinceLastLogin; accountVm.HasArrangement = account.HasArrangement; accountVm.PlanPendingTransfer = account.PlanPendingTransfer; accountVm.PlanTransferredFrom = account.PlanTransferredFrom; if (!string.IsNullOrEmpty(accountVm.PlanTransferredFrom)) { accountVm.PlanTransferredFromAccounts = accountVm.PlanTransferredFrom.Split(',').ToList(); accountVm.PlanTransferredFromMessage = _mapperHelper.DerivePlanTransferredFromMessage(accountVm.PlanTransferredFromAccounts); } accountVm.NeverAllowPlanTransfer = account.NeverAllowPlanTransfer; if (account.DiscountedBalance != null) { accountVm.DiscountedBalanceTextOptional = account.DiscountedBalance.Value.ToString("C", CultureInfo.CurrentCulture); } if (account.AccountStatusIsWithSolicitors) { accountVm.SolicitorsRedirectLink = _portalSettings.SolicitorsRedirectUrl; } accountVm.IsPaymentButtonAvailable = account.CanMakePayment; accountVm.CanAmendPlan = account.CanAmendPlan; if (account.AccountStatusIsViewOnly) { accountVm.DiscountAvailableLinkTextOptional = null; } if (account.AccountStatusIsClosed) { accountVm.ArrearsMessage = null; accountVm.DiscountAvailableLinkTextOptional = null; accountVm.IsPaymentButtonAvailable = false; accountVm.CanAmendPlan = false; } destination.Accounts.Add(accountVm); } destination.LowellFinancialAccountSurrogateKey = lowellFinancialAccountSurrogateKey; if (source.IncomeAndExpenditure != null) { destination.IncomeAndExpenditureSubmitted = true; destination.IncomeAndExpenditureExpired = source.IncomeAndExpenditure.Created.AddMonths(6).Date < DateTime.Now.Date; destination.IandELessThanOrIs12MonthsOld = source.IncomeAndExpenditure.Created.AddMonths(12).Date >= DateTime.Now.Date; } destination.IncomeAndExpenditureSubmitted = source.IncomeAndExpenditure != null; destination.NewAccounts = destination.Accounts.Where(x => x.AddedSinceLastLogin && !x.HasArrangement).ToList(); destination.DisposableIncome = source.IncomeAndExpenditure?.DisposableIncome; //Sort accounts so that any with plans pending transfer or have had plans transferred to are first destination.Accounts = destination.Accounts .OrderByDescending(x => x.PlanPendingTransfer || !String.IsNullOrEmpty(x.PlanTransferredFrom)).ToList(); return(destination); }