public MortgageInvestmentProfileModel GenerateProfiles(List<LiabilityBase> liabilities) { MortgageInvestmentProfileModel model = new MortgageInvestmentProfileModel { data = new List<MortgageInvestmentProfileItem>() }; var mortgageAndHomes = liabilities.OfType<MortgageAndHomeLiability>(); foreach (var mortgageAndHome in mortgageAndHomes) { double monthlyRepayment = 0; foreach (var activity in mortgageAndHome.GetActivitiesSync().OfType<FinancialActivity>()) { monthlyRepayment += activity.Expenses.Sum(e => e.Amount); } model.data.Add(new MortgageInvestmentProfileItem { propertyName = ((PropertyType)Int32.Parse(mortgageAndHome.Property.PropertyType)).ToString(), address = mortgageAndHome.Property.FullAddress, currency = mortgageAndHome.CurrencyType.ToString(), marketValue = mortgageAndHome.Property.GetTotalMarketValue(), outstandingLoan = mortgageAndHome.CurrentBalance, currentPropertyGearingRatio = mortgageAndHome.CurrentPropertyGearingRatio, institution = mortgageAndHome.LoanProviderInstitution, typeOfRates = mortgageAndHome.TypeOfMortgageRates.ToString(), monthlyRepaymentAmount = monthlyRepayment, loanContractTerm = mortgageAndHome.LoanContractTermInYears, loanExpiryDate = mortgageAndHome.ExpiryDate, RepaymentType = mortgageAndHome.LoanRepaymentType.ToString(), currentLoanBalance = mortgageAndHome.CurrentBalance, currentFinancialYearInterest = mortgageAndHome.CurrentFiancialYearInterest, interestRates = mortgageAndHome.CurrentFiancialYearInterest, startDate = mortgageAndHome.GrantedOn, NumberOfYearsToExpiry = (mortgageAndHome.ExpiryDate - mortgageAndHome.GrantedOn).TotalDays / 365, numberOfYearsToDate = (DateTime.Now - mortgageAndHome.GrantedOn).TotalDays / 365, suitability = mortgageAndHome.Property.GetRating().TotalScore }); } return model; }
public MortgageInvestmentProfileModel GetProfiles_Client() { Client client = edisRepo.GetClientSync(User.Identity.GetUserId(), DateTime.Now); ClientGroup clientGroup = edisRepo.GetClientGroupSync(client.ClientGroupId, DateTime.Now); if (clientGroup.MainClientId == client.Id) { List<GroupAccount> groupAccounts = edisRepo.GetAccountsForClientGroupSync(clientGroup.ClientGroupNumber, DateTime.Now); List<ClientAccount> clientAccounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now); MortgageInvestmentProfileModel model = new MortgageInvestmentProfileModel { data = new List<MortgageInvestmentProfileItem>() }; List<LiabilityBase> liabilities = new List<LiabilityBase>(); foreach (var account in groupAccounts) { liabilities.AddRange(account.GetLiabilitiesSync()); } foreach (var account in clientAccounts) { liabilities.AddRange(account.GetLiabilitiesSync()); } var mortgageAndHomes = liabilities.OfType<MortgageAndHomeLiability>(); foreach (var mortgageAndHome in mortgageAndHomes) { double monthlyRepayment = 0; foreach (var activity in mortgageAndHome.GetActivitiesSync().OfType<FinancialActivity>()) { monthlyRepayment += activity.Incomes.Sum(i => i.Amount); } model.data.Add(new MortgageInvestmentProfileItem { propertyName = mortgageAndHome.Property.PropertyType, address = mortgageAndHome.Property.FullAddress, currency = mortgageAndHome.CurrencyType.ToString(), marketValue = mortgageAndHome.Property.GetTotalMarketValue(), outstandingLoan = mortgageAndHome.CurrentBalance, currentPropertyGearingRatio = mortgageAndHome.CurrentPropertyGearingRatio, institution = mortgageAndHome.LoanProviderInstitution, typeOfRates = mortgageAndHome.TypeOfMortgageRates.ToString(), monthlyRepaymentAmount = monthlyRepayment, loanContractTerm = mortgageAndHome.LoanContractTermInYears, loanExpiryDate = mortgageAndHome.ExpiryDate, RepaymentType = mortgageAndHome.LoanRepaymentType.ToString(), currentLoanBalance = mortgageAndHome.CurrentBalance, currentFinancialYearInterest = mortgageAndHome.CurrentFiancialYearInterest }); } return model; } else { List<ClientAccount> accounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now); MortgageInvestmentProfileModel model = new MortgageInvestmentProfileModel { data = new List<MortgageInvestmentProfileItem>() }; List<LiabilityBase> liabilities = new List<LiabilityBase>(); foreach (var account in accounts) { liabilities.AddRange(account.GetLiabilitiesSync()); } var mortgageAndHomes = liabilities.OfType<MortgageAndHomeLiability>(); foreach (var mortgageAndHome in mortgageAndHomes) { double monthlyRepayment = 0; foreach (var activity in mortgageAndHome.GetActivitiesSync().OfType<FinancialActivity>()) { monthlyRepayment += activity.Incomes.Sum(i => i.Amount); } model.data.Add(new MortgageInvestmentProfileItem { propertyName = mortgageAndHome.Property.PropertyType, address = mortgageAndHome.Property.FullAddress, currency = mortgageAndHome.CurrencyType.ToString(), marketValue = mortgageAndHome.Property.GetTotalMarketValue(), outstandingLoan = mortgageAndHome.CurrentBalance, currentPropertyGearingRatio = mortgageAndHome.CurrentPropertyGearingRatio, institution = mortgageAndHome.LoanProviderInstitution, typeOfRates = mortgageAndHome.TypeOfMortgageRates.ToString(), monthlyRepaymentAmount = monthlyRepayment, loanContractTerm = mortgageAndHome.LoanContractTermInYears, loanExpiryDate = mortgageAndHome.ExpiryDate, RepaymentType = mortgageAndHome.LoanRepaymentType.ToString(), currentLoanBalance = mortgageAndHome.CurrentBalance, currentFinancialYearInterest = mortgageAndHome.CurrentFiancialYearInterest }); } return model; } }