public SummaryGeneralInfoFCL GetGeneralInfo_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); double totalCost = 0; double totalMarketValue = 0; double coupon = 0; double faceValue = 0; foreach (var account in groupAccounts) { List<AssetBase> assets = account.GetAssetsSync().OfType<FixedIncome>().Cast<AssetBase>().ToList(); var fixedIncomes = assets.OfType<FixedIncome>(); foreach (var asset in assets) { totalCost += asset.GetCost().Total; totalMarketValue += asset.GetTotalMarketValue(); faceValue += asset.LatestPrice; } foreach (var income in fixedIncomes) { coupon += income.CouponRate == null ? 0 : (double)income.CouponRate; } } foreach (var account in clientAccounts) { List<AssetBase> assets = account.GetAssetsSync().OfType<FixedIncome>().Cast<AssetBase>().ToList(); var fixedIncomes = assets.OfType<FixedIncome>(); foreach (var asset in assets) { totalCost += asset.GetCost().Total; totalMarketValue += asset.GetTotalMarketValue(); faceValue += asset.LatestPrice; } foreach (var income in fixedIncomes) { coupon += income.CouponRate == null ? 0 : (double)income.CouponRate; } } SummaryGeneralInfoFCL summary = new SummaryGeneralInfoFCL { cost = totalCost, marketValue = totalMarketValue, pl = totalMarketValue - totalCost, plp = totalCost == 0 ? 0 : (totalMarketValue - totalCost) / totalCost * 100, aveCoupon = coupon, faceValue = faceValue }; return summary; } else { List<ClientAccount> accounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now); double totalCost = 0; double totalMarketValue = 0; double coupon = 0; double faceValue = 0; foreach (var account in accounts) { List<AssetBase> assets = account.GetAssetsSync().OfType<FixedIncome>().Cast<AssetBase>().ToList(); var fixedIncomes = assets.OfType<FixedIncome>(); foreach (var asset in assets) { totalCost += asset.GetCost().Total; totalMarketValue += asset.GetTotalMarketValue(); faceValue += asset.LatestPrice; } foreach (var income in fixedIncomes) { coupon += income.CouponRate == null ? 0 : (double)income.CouponRate; } } SummaryGeneralInfoFCL summary = new SummaryGeneralInfoFCL { cost = totalCost, marketValue = totalMarketValue, pl = totalMarketValue - totalCost, plp = totalCost == 0 ? 0 : (totalMarketValue - totalCost) / totalCost * 100, faceValue = faceValue, aveCoupon = coupon }; return summary; } }
public SummaryGeneralInfoFCL GenerateGeneralInforModel(List<AssetBase> assets) { double totalCost = 0; double totalMarketValue = 0; double faceValue = 0; foreach (var asset in assets) { totalCost += asset.GetCost().Total; totalMarketValue += asset.GetTotalMarketValue(); faceValue += asset.LatestPrice; } SummaryGeneralInfoFCL summary = new SummaryGeneralInfoFCL { cost = totalCost, marketValue = totalMarketValue, pl = totalMarketValue - totalCost, plp = totalCost == 0 ? 0 : (totalMarketValue - totalCost) / totalCost * 100, aveCoupon = assets.Count() == 0? 0 : assets.OfType<FixedIncome>().Average(i => i.CouponRate == null ? 0 : (double)i.CouponRate) }; return summary; }