public void AddBudgetExpense(BudgetExpense budgetExpense) { context.BudgetExpenses.Add(budgetExpense); Expense expense = context.Expenses.Find(budgetExpense.ExpenseId); Budget budget = GetBudget(budgetExpense.BudgetId); if (expense.IsManditory) budget.ManditoryExpenses += budgetExpense.Amount; else budget.DiscretionaryExpenses += budgetExpense.Amount; SaveChanges(); }
public ActionResult CreateExpense(BudgetExpense model) { repository.AddBudgetExpense(model); return RedirectToAction("Expenses", new { id = model.BudgetId }); }
public ActionResult EditExpense(BudgetExpense model) { if (ModelState.IsValid) { model.Amount += model.AddAmount; repository.UpdateBudgetExpense(model); return RedirectToAction("Expenses", new { id = model.BudgetId }); } return View(model); }
public ActionResult DeleteExpense(BudgetExpense budgetExpense) { try { repository.DeleteBudgetExpense(budgetExpense); return RedirectToAction("Expenses", new { id = budgetExpense.BudgetId }); } catch { return View(); } }
public void UpdateBudgetExpense(BudgetExpense budgetExpense) { BudgetExpense budgetExpenseToUpdate = GetBudgetExpense(budgetExpense.BudgetExpenseId); // subtract old amount from budget and add new amount if (budgetExpenseToUpdate.Expense.IsManditory) { budgetExpenseToUpdate.Budget.ManditoryExpenses -= budgetExpenseToUpdate.Amount; budgetExpenseToUpdate.Budget.ManditoryExpenses += budgetExpense.Amount; } else { budgetExpenseToUpdate.Budget.DiscretionaryExpenses -= budgetExpenseToUpdate.Amount; budgetExpenseToUpdate.Budget.DiscretionaryExpenses += budgetExpense.Amount; } budgetExpenseToUpdate.Amount = budgetExpense.Amount; SaveChanges(); }
public void DeleteBudgetExpense(BudgetExpense budgetExpense) { budgetExpense = GetBudgetExpense(budgetExpense.BudgetExpenseId); if (budgetExpense.Expense.IsManditory) budgetExpense.Budget.ManditoryExpenses -= budgetExpense.Amount; else budgetExpense.Budget.DiscretionaryExpenses -= budgetExpense.Amount; context.BudgetExpenses.Remove(budgetExpense); SaveChanges(); }