コード例 #1
0
        public int AddExpense(NewExpenseVm newExp)
        {
            var exp = _mapper.Map <Expense>(newExp);
            int id  = _expenseRepo.AddExpense(exp);

            return(id);
        }
コード例 #2
0
        public IActionResult CreateExpense()
        {
            var userId = _userManager.GetUserId(HttpContext.User);

            //Create view model (with user's categories and userId) for new expense
            NewExpenseVm model = _expenseService.CreateNewExpense(userId);

            return(View(model));
        }
コード例 #3
0
        public NewExpenseVm CreateNewExpense(string userId)
        {
            int budgetId   = _budgetRepo.GetBudgetIdByUserId(userId);
            var categories = _detailedCRepo.GetDetailedCategoriesOfUser(userId);
            var model      = new NewExpenseVm()
            {
                Categories = categories, UserId = userId, BudgetId = budgetId
            };

            return(model);
        }
コード例 #4
0
        public IActionResult CreateExpense(NewExpenseVm model)
        {
            //Try to add expense to the database. If success, add amount to the user's budget.
            var id = _expenseService.AddExpense(model);

            if (id != 0)
            {
                _budgetService.ChangeSum(id, 1);
            }

            return(RedirectToAction("Index"));
        }