public ViewResult List(string category)
        {
            string _category = category;
            IEnumerable <RealEstate> realEstates;

            string currentCategory = string.Empty;

            if (string.IsNullOrEmpty(category))
            {
                realEstates     = _realEstateRepository.RealEstates.OrderBy(r => r.RealEstateId);
                currentCategory = "All Real Estates";
            }
            else
            {
                realEstates     = _realEstateRepository.RealEstates.Where(r => r.Category.Description.Equals(_category));
                currentCategory = _category;
            }

            var realEstateListViewModel = new RealEstateListViewModel
            {
                RealEstates     = realEstates,
                CurrentCategory = currentCategory
            };

            return(View(realEstateListViewModel));
        }
예제 #2
0
        public static RealEstateListViewModel GetRealEstateByUser(string username)
        {
            Entities entities = new Entities();
            RealEstateListViewModel result = new RealEstateListViewModel();
            DateTime current = DateTime.Now;

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

            foreach (var realEstate in realEstates)
            {
                RealEstateViewModel realEstateViewModel = new RealEstateViewModel();
                realEstateViewModel.Id    = realEstate.Id;
                realEstateViewModel.Name  = realEstate.AssetName;
                realEstateViewModel.Value = realEstate.Value;
                if (realEstate.Incomes1.Where(x => !x.DisabledDate.HasValue).Any())
                {
                    realEstateViewModel.Income = realEstate.Incomes1.FirstOrDefault().Value;
                }
                else
                {
                    realEstateViewModel.Income = 0;
                }
                realEstateViewModel.AnnualIncome = realEstateViewModel.Income * 12;
                realEstateViewModel.RentYield    = realEstateViewModel.Value > 0 ? realEstateViewModel.AnnualIncome / realEstateViewModel.Value : 0;

                foreach (var liability in realEstate.Liabilities.Where(x => !x.DisabledDate.HasValue))
                {
                    RealEstateLiabilityViewModel liabilityViewModel = RealEstateLiabilityQueries.CreateViewModel(liability);
                    realEstateViewModel.Liabilities.Add(liabilityViewModel);
                }

                var liabilities = realEstateViewModel.Liabilities.Where(x => x.StartDate <= current && x.EndDate >= current);
                realEstateViewModel.TotalLiabilityValue  = liabilities.Select(x => x.Value.Value).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalOriginalPayment = liabilities.Select(x => x.MonthlyOriginalPayment).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalInterestPayment = liabilities.Select(x => x.MonthlyInterestPayment).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalMonthlyPayment  = liabilities.Select(x => x.TotalMonthlyPayment).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalPayment         = liabilities.Select(x => x.TotalPayment).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalRemainedValue   = liabilities.Select(x => x.RemainedValue).DefaultIfEmpty(0).Sum();
                realEstateViewModel.TotalInterestRate    = realEstateViewModel.TotalLiabilityValue > 0 ? liabilities.Select(x => x.OriginalInterestPayment).DefaultIfEmpty(0).Sum() / realEstateViewModel.TotalLiabilityValue * 12 : 0;
                realEstateViewModel.RowSpan = realEstateViewModel.Liabilities.Any() ? realEstateViewModel.Liabilities.Count() + 3 : 2;

                result.RealEstates.Add(realEstateViewModel);
            }

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

            return(result);
        }
예제 #3
0
        public ActionResult _RealEstateTable()
        {
            RealEstateListViewModel model = RealEstateQueries.GetRealEstateByUser(UserQueries.GetCurrentUsername());

            return(PartialView(model));
        }