public ActionResult Create() { ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category"); Expense _Expense = new Expense(); _Expense.Date = DateTime.Today; return View(_Expense); }
public ActionResult Create(Expense Expense, FormCollection collection) { if (ModelState.IsValid) { this.UpdateModel(Expense); svc.Save(Expense); return RedirectToAction("Details", new { id = Expense.Id }); } ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category"); return View(Expense); }
public ActionResult Edit(int id, Expense Expense, FormCollection collection) { Expense _entity = svc.GetById(id); if (ModelState.IsValid) { _entity.Date = Convert.ToDateTime(collection["Date"]); _entity.Amount = Convert.ToDecimal(collection["Amount"]); _entity.Remark = collection["Remark"]; _entity.CategoryId = int.Parse(collection["CategoryId"]); try { svc.Update(_entity); } catch (Exception e) { } return RedirectToAction("Details", new { id = _entity.Id }); } ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category", _entity.CategoryId); return View(_entity); }