public ActionResult Create(int expenseId, int? userId) { var expense = Expenses.FetchById(expenseId); if(expense == null) return HttpNotFound(); var model = new Models.ExpenseItemCreateAndEditModel(true, expense, Users.FetchAll()); model.ExpenseItem = new Models.ExpenseItemModel(ExpenseItems.CreateNew(expense)); model.ExpenseItem.CreatorUserId = userId; return View("CreateAndEdit", model); }
public ActionResult Create(int expenseId, [Bind(Prefix = "ExpenseItem")] Models.ExpenseItemModel value) { var expense = Expenses.FetchById(expenseId); if (expense == null) return HttpNotFound(); if (!ViewData.ModelState.IsValid) { var model = new Models.ExpenseItemCreateAndEditModel(true, expense, Users.FetchAll()); model.ExpenseItem = value; return View("CreateAndEdit", model); } // apply to BO value.ApplyToBO(ExpenseItems.CreateNew(expense), Users); // save Context.SaveChanges(); return RedirectToAction("Details", "Expenses", new { id = expense.Id }); }
public ActionResult Edit(int id) { var item = ExpenseItems.FetchById(id); if (item == null) return HttpNotFound(); var model = new Models.ExpenseItemCreateAndEditModel(false, item.Expense, Users.FetchAll()); model.ExpenseItem = new Models.ExpenseItemModel(item); return View("CreateAndEdit", model); }