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