public void ConfigureCategorySpending(BudgetItemExpense budgetItemExpense, Budget budget) { switch (budgetItemExpense.Category) { case ("Coffee"): budget.CoffeeCategorySpent += budgetItemExpense.Amount; break; case ("Dining Out"): budget.DiningOutCategorySpent += budgetItemExpense.Amount; break; case ("Entertainment"): budget.EntertainmentCategorySpent += budgetItemExpense.Amount; break; case ("Gas"): budget.GasCategorySpent += budgetItemExpense.Amount; break; case ("Groceries"): budget.GroceriesCategorySpent += budgetItemExpense.Amount; break; } _repo.Budgets.Update(budget); _repo.Save(); }
public ActionResult CreateBudgetItemExpense(BudgetItemExpense budgetItemExpense) { try { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var budgeteer = _repo.Budgeteers.GetBudgeteerByUserId(userId); var budget = _repo.Budgets.GetBudgetByBudgeteerIdMonthAndYear(budgeteer.BudgeteerId, DateTime.Now.Month, DateTime.Now.Year); var wallet = _repo.Wallets.GetWallet(budgeteer.WalletId); var newBudgetItemExpense = new BudgetItemExpense { BudgetItemExpenseName = budgetItemExpense.BudgetItemExpenseName, Category = budgetItemExpense.Category, Amount = budgetItemExpense.Amount, BudgetId = budget.BudgetId }; _repo.BudgetItemExpenses.Create(newBudgetItemExpense); _repo.Save(); budget.MonthlyBudgetItemMoney += budgetItemExpense.Amount; budget.MonthlyTotalMoney += budgetItemExpense.Amount; _repo.Budgets.Update(budget); _repo.Save(); wallet.TotalBudgetItemMoney += budgetItemExpense.Amount; wallet.TotalMoney += budgetItemExpense.Amount; _repo.Wallets.Update(wallet); _repo.Save(); ConfigureCategorySpending(newBudgetItemExpense, budget); return(RedirectToAction(nameof(Index))); } catch { return(View(budgetItemExpense)); } }