// GET: /Expense/Edit public ActionResult Edit(int id) { var expense = expenseRepository.GetById(id); var viewModel = new ExpenseFormModel(expense); var categories = categoryRepository.GetAll(); viewModel.Category = categories.ToSelectListItems(expense.Category.CategoryId); return View(viewModel); }
public ActionResult Create() { var viewModel = new ExpenseFormModel(); var categories = categoryRepository.GetAll(); viewModel.Category = categories.ToSelectListItems(-1); viewModel.Date = DateTime.Today; return View(viewModel); }
public ActionResult Save(ExpenseFormModel form) { Category category = categoryRepository.GetById(form.CategoryId); if (ModelState.IsValid) { var command = new CreateOrUpdateExpenseCommand { ExpenseId = form.ExpenseId, Category = category, Date = form.Date, Transaction = form.Transaction, Amount = form.Amount }; var result = commandBus.Submit(command); if (result.Success) return RedirectToAction("Index"); } if (form.ExpenseId == 0) return View("Create", form); else return View("Edit", form); }