コード例 #1
0
        //================
        //-----BUDGET-----
        //================

        // GET: Budget
        public ActionResult Index()
        {
            var householdId = User.Identity.GetHouseholdId();
            var model       = new BudgetIndexViewModel();

            if (householdId != null)
            {
                model.Budgets = _budgetManager.GetAll(householdId.Value).Select(b => new BudgetViewModel
                {
                    Id          = b.Id,
                    Duration    = b.Duration,
                    Total       = b.BudgetItems.Select(s => s.Amount).DefaultIfEmpty().Sum(),
                    BudgetItems = b.BudgetItems.Select(bi => new BudgetItemViewModel
                    {
                        Id           = bi.Id,
                        Amount       = bi.Amount,
                        CategoryId   = bi.CategoryId,
                        CategoryName = bi.Category.Name
                    }).ToList()
                }).ToList();
                model.Categories = _categoryManager.GetAll(householdId.Value).Select(c => new CategoryViewModel {
                    Id = c.Id, Name = c.Name, CanEdit = c.HouseholdId.HasValue
                }).ToList();
            }
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            var viewModel = new BudgetIndexViewModel()
            {
                Budget           = await _repo.GetBudget(),
                TotalForTheMonth = await _repo.GetTotalsForBudget(),
                Categories       = await _repo.GetList <Category>()
            };

            return(View(viewModel));
        }
コード例 #3
0
        public BudgetIndexViewModel MapBudgetIndexViewModel(string username)
        {
            var budgets = FinancialPlannerRepository.GetBudgets()
                          .Where(m => m.Username == username);

            var vm = new BudgetIndexViewModel
            {
                Budgets = SetViewModelsService.SetBudgetViewModels(budgets)
            };

            return(vm);
        }
コード例 #4
0
        // GET: Budgets
        public ActionResult Index()
        {
            var budgets             = db.Budgets.Include(b => b.BudgetCategory).ToList();
            BudgetIndexViewModel vm = new BudgetIndexViewModel();

            vm.Budgets = budgets;
            IEnumerable <Transaction> transactions = new List <Transaction>();
            decimal transactionSum = 0;
            int     i = 0;

            vm.CurrentAmounts = new decimal[budgets.Count];
            foreach (var budget in vm.Budgets)
            {
                transactions   = db.Transactions.Where(t => t.BudgetCategoryId == budget.BudgetCategoryId).ToList();
                transactionSum = budget.Amount;
                foreach (var transaction in transactions)
                {
                    if (transaction.Expense)
                    {
                        transactionSum -= transaction.Amount;
                    }
                    else
                    {
                        transactionSum += transaction.Amount;
                    }
                }
                vm.CurrentAmounts[i] = transactionSum;
                i++;
            }
            Household household = db.Households.Find(Convert.ToInt32(User.Identity.GetHouseholdId()));

            ViewBag.HouseholdName = household.Name;
            string temp = TempData["noAccounts"] as string;

            if (temp == "noAccounts")
            {
                ViewBag.NoAccounts = "You need to create an account for this household to utilize transaction functionality";
            }
            return(View(vm));
        }