public static AssetListViewModel GetLiabilityListViewModelByAssetListViewModel(AssetListViewModel assetListViewModel)
        {
            Entities           entities = new Entities();
            AssetListViewModel result   = new AssetListViewModel();

            result.Type = assetListViewModel.Type;
            foreach (var assetViewModel in assetListViewModel.List)
            {
                assetViewModel.LiabilityList        = GetLiabilityViewModelByAssetViewModel(assetViewModel);
                assetViewModel.TotalMortgageValue   = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.Liability.Value);
                assetViewModel.TotalInterestPayment = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.MonthlyInterestPayment);
                assetViewModel.TotalOriginalPayment = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.MonthlyOriginalPayment);
                assetViewModel.TotalMonthlyPayment  = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.MonthlyPayment);
                assetViewModel.TotalAnnualPayment   = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.AnnualPayment);
                assetViewModel.TotalRemainingValue  = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue).Sum(x => x.RemainedValue);
                if (assetListViewModel.Type == (int)Constants.Constants.ASSET_TYPE.REAL_ESTATE || assetListViewModel.Type == (int)Constants.Constants.ASSET_TYPE.BUSINESS ||
                    assetListViewModel.Type == (int)Constants.Constants.ASSET_TYPE.STOCK)
                {
                    double currentTotalMortgageValue = assetViewModel.LiabilityList.List.Where(x => !x.Liability.ParentLiabilityId.HasValue && x.CurrentInterestRate != 0).Sum(x => x.Liability.Value);
                    if (assetViewModel.LiabilityList.List.Count > 0)
                    {
                        if (assetViewModel.LiabilityList.List.FirstOrDefault().Liability.InterestType == (int)Constants.Constants.INTEREST_TYPE.REDUCED)
                        {
                            assetViewModel.AverageInterestRate = assetViewModel.TotalInterestPayment / assetViewModel.TotalRemainingValue * 1200;
                        }
                        else
                        {
                            assetViewModel.AverageInterestRate = assetViewModel.TotalInterestPayment / assetViewModel.TotalMortgageValue * 1200;
                        }
                    }
                }
                else
                {
                    assetViewModel.AverageInterestRate = assetViewModel.TotalMortgageValue > 0 ? assetViewModel.TotalAnnualPayment / assetViewModel.TotalMortgageValue * 100 : 0;
                }
                result.List.Add(assetViewModel);
            }
            result.TotalMonthlyIncome = result.Type != (int)Constants.Constants.ASSET_TYPE.INSURANCE && result.Type != (int)Constants.Constants.ASSET_TYPE.STOCK ? result.List.Select(x => x.Income.Value).DefaultIfEmpty(0).Sum() : 0;
            result.TotalValue         = result.List.Select(x => x.Asset.Value).DefaultIfEmpty(0).Sum();
            return(result);
        }
Пример #2
0
        // GET: /<controller>/
        public ViewResult List()
        {
            _logger.LogTrace("TRACE");
            _logger.LogDebug("DEBUG");
            _logger.LogInformation("INFORMATION");
            _logger.LogWarning("WARNING");
            _logger.LogError("ERROR");
            _logger.LogCritical("CRITICAL");
            ViewBag.Title = "All Assets";
            AssetListViewModel vm = new AssetListViewModel();

            vm.Assets = GetAssetsList();

            var user        = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var userDetails = _dbcontext.Users.Where(x => x.Id == user).FirstOrDefault();

            vm.FirstName = userDetails.FirstName;
            vm.LastName  = userDetails.LastName;

            return(View(vm));
        }
Пример #3
0
        // GET: Asset
        public ActionResult Index(int?projectId)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                AssetListViewModel assetList;
                if (projectId == null)
                {
                    // Returns all assets
                    assetList = new AssetListViewModel
                    {
                        //Convert each Asset to an AssetViewModel
                        Assets = assetRepoContext.Assets.Select(a => new AssetViewModel
                        {
                            AssetId = a.AssetId,
                            Project = new ProjectPopulatedViewModel
                            {
                                ProjectId = a.ProjectId,
                                Title     = a.Project.Title,
                                Category  = new ProjectCategoryViewModel
                                {
                                    ProjectCategoryId = a.Project.ProjectCategoryId,
                                    Name = a.Project.ProjectCategory.Name
                                },
                                Creator = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.CreatorId,
                                    Name          = a.Project.Creator.Name
                                },
                                CreationDateTime = a.Project.CreationDateTime,
                                LastUpdater      = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.LastUpdaterId,
                                    Name          = a.Project.LastUpdater.Name
                                },
                                LastUpdateDateTime = a.Project.LastUpdateDateTime,
                                Description        = a.Project.Description,
                                IsActive           = a.Project.IsActive
                            },
                            Title = a.Title,
                            TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                            {
                                AssetTypeSubtypePairingId = a.AssetTypeSubtypePairingId,
                                Type = new AssetTypeViewModel
                                {
                                    AssetTypeId = a.AssetTypeSubtypePairing.AssetTypeId,
                                    Name        = a.AssetTypeSubtypePairing.AssetType.Name
                                },
                                Subtype = new AssetSubtypeViewModel
                                {
                                    AssetSubtypeId = a.AssetTypeSubtypePairing.AssetSubtypeId,
                                    Name           = a.AssetTypeSubtypePairing.AssetSubtype.Name
                                }
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.CreatorId,
                                Name          = a.Creator.Name
                            },
                            CreationDateTime = a.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.LastUpdaterId,
                                Name          = a.LastUpdater.Name
                            },
                            LastUpdateDateTime = a.LastUpdateDateTime,
                            Comment            = a.Comment,
                            FilePlaceholder    = a.FilePlaceholder,
                            ProjectRouteId     = projectId
                        }).ToList()
                    };
                }
                else
                {
                    //Returns all assets for a given project
                    assetList = new AssetListViewModel
                    {
                        //Convert each Asset to an AssetViewModel
                        Assets = assetRepoContext.Assets
                                 .Select(a => new AssetViewModel
                        {
                            AssetId = a.AssetId,
                            Project = new ProjectPopulatedViewModel
                            {
                                ProjectId = a.ProjectId,
                                Title     = a.Project.Title,
                                Category  = new ProjectCategoryViewModel
                                {
                                    ProjectCategoryId = a.Project.ProjectCategoryId,
                                    Name = a.Project.ProjectCategory.Name
                                },
                                Creator = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.CreatorId,
                                    Name          = a.Project.Creator.Name
                                },
                                CreationDateTime = a.Project.CreationDateTime,
                                LastUpdater      = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.LastUpdaterId,
                                    Name          = a.Project.LastUpdater.Name
                                },
                                LastUpdateDateTime = a.Project.LastUpdateDateTime,
                                Description        = a.Project.Description,
                                IsActive           = a.Project.IsActive
                            },
                            Title = a.Title,
                            TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                            {
                                AssetTypeSubtypePairingId = a.AssetTypeSubtypePairingId,
                                Type = new AssetTypeViewModel
                                {
                                    AssetTypeId = a.AssetTypeSubtypePairing.AssetTypeId,
                                    Name        = a.AssetTypeSubtypePairing.AssetType.Name
                                },
                                Subtype = new AssetSubtypeViewModel
                                {
                                    AssetSubtypeId = a.AssetTypeSubtypePairing.AssetSubtypeId,
                                    Name           = a.AssetTypeSubtypePairing.AssetSubtype.Name
                                }
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.CreatorId,
                                Name          = a.Creator.Name
                            },
                            CreationDateTime = a.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.LastUpdaterId,
                                Name          = a.LastUpdater.Name
                            },
                            LastUpdateDateTime = a.LastUpdateDateTime,
                            Comment            = a.Comment,
                            FilePlaceholder    = a.FilePlaceholder,
                            ProjectRouteId     = projectId
                        })
                                 .Where(a => a.Project.ProjectId == projectId)
                                 .ToList()
                    };
                }

                assetList.ProjectRouteId = projectId;

                assetList.TotalAssets = assetList.Assets.Count;

                return(View(assetList));
            }
        }
Пример #4
0
 public AssetList()
 {
     InitializeComponent();
     vm             = new AssetListViewModel();
     this.Unloaded += AssetList_Unloaded;
 }
        public ActionResult _Report(int type)
        {
            AssetListViewModel model = AssetQueries.GetAssetByUser(UserQueries.GetCurrentUsername(), type);

            return(View(model));
        }