Beispiel #1
0
        public static BankDepositListViewModel GetBankDepositByUser(string username)
        {
            Entities entities     = new Entities();
            var      bankDeposits = entities.Assets.Where(x => x.Username.Equals(username) &&
                                                          x.AssetType == (int)Constants.Constants.ASSET_TYPE.BANK_DEPOSIT &&
                                                          !x.DisabledDate.HasValue).OrderBy(x => x.AssetName).ToList();
            BankDepositListViewModel result = new BankDepositListViewModel();

            foreach (var bankDeposit in bankDeposits)
            {
                BankDepositViewModel viewModel = new BankDepositViewModel
                {
                    Id                = bankDeposit.Id,
                    Name              = bankDeposit.AssetName,
                    Value             = bankDeposit.Value,
                    StartDate         = bankDeposit.StartDate.Value,
                    EndDate           = bankDeposit.EndDate.Value,
                    Income            = bankDeposit.InterestRatePerX.Value == (int)Constants.Constants.INTEREST_RATE_PER.MONTH ? bankDeposit.Value * bankDeposit.InterestRate.Value / 100 : bankDeposit.Value * bankDeposit.InterestRate.Value / 1200,
                    InterestRate      = bankDeposit.InterestRate.Value / 100,
                    InterestRatePerX  = Helper.GetInterestTypePerX(bankDeposit.InterestRatePerX.Value),
                    InterestObtainWay = Helper.GetObtainWay(bankDeposit.ObtainedBy.Value),
                    PaymentPeriod     = Helper.CalculateTimePeriod(bankDeposit.StartDate.Value, bankDeposit.EndDate.Value),
                    Note              = bankDeposit.Note
                };
                viewModel.AnnualIncome = viewModel.Income * 12;
                result.BankDeposits.Add(viewModel);
            }

            result.TotalValue        = result.BankDeposits.Sum(x => x.Value);
            result.TotalIncome       = result.BankDeposits.Sum(x => x.Income);
            result.TotalAnnualIncome = result.BankDeposits.Sum(x => x.AnnualIncome);
            result.TotalInterestRate = result.TotalValue > 0 ? result.TotalAnnualIncome / result.TotalValue : 0;
            result.IsInitialized     = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
        public ActionResult _BankDepositTable()
        {
            BankDepositListViewModel model = BankDepositQueries.GetBankDepositByUser(UserQueries.GetCurrentUsername());

            return(PartialView(model));
        }