public static OtherAssetListViewModel GetOtherAssetByUser(string username)
        {
            Entities entities = new Entities();
            OtherAssetListViewModel result = new OtherAssetListViewModel();
            DateTime current = DateTime.Now;

            var otherAssets = entities.Assets.Include("Incomes").Include("Liabilities").Where(x => x.Username.Equals(username) &&
                                                                                              x.AssetType == (int)Constants.Constants.ASSET_TYPE.OTHERS &&
                                                                                              !x.DisabledDate.HasValue);

            foreach (var otherAsset in otherAssets)
            {
                OtherAssetViewModel otherAssetViewModel = new OtherAssetViewModel();
                otherAssetViewModel.Id    = otherAsset.Id;
                otherAssetViewModel.Name  = otherAsset.AssetName;
                otherAssetViewModel.Value = otherAsset.Value;
                if (otherAsset.Incomes1.Where(x => !x.DisabledDate.HasValue).Any())
                {
                    otherAssetViewModel.Income = otherAsset.Incomes1.FirstOrDefault().Value;
                }
                else
                {
                    otherAssetViewModel.Income = 0;
                }
                otherAssetViewModel.AnnualIncome = otherAssetViewModel.Income * 12;
                otherAssetViewModel.RentYield    = otherAssetViewModel.AnnualIncome / otherAssetViewModel.Value;

                result.Assets.Add(otherAssetViewModel);
            }

            result.TotalValue         = result.Assets.Select(x => x.Value).DefaultIfEmpty(0).Sum();
            result.TotalMonthlyIncome = result.Assets.Select(x => x.Income).DefaultIfEmpty(0).Sum();
            result.TotalAnnualIncome  = result.TotalMonthlyIncome * 12;
            result.TotalRentYield     = result.TotalMonthlyIncome / result.TotalValue;
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
Esempio n. 2
0
        public ActionResult _OtherAssetTable()
        {
            OtherAssetListViewModel model = OtherAssetQueries.GetOtherAssetByUser(UserQueries.GetCurrentUsername());

            return(PartialView(model));
        }