public int AddExpense(NewExpenseVm newExp) { var exp = _mapper.Map <Expense>(newExp); int id = _expenseRepo.AddExpense(exp); return(id); }
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)); }
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); }
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")); }