public ActionResult Edit(int id, FormCollection collection, DEPT_TBL model) { try { using (DMSDbEntities db = new DMSDbEntities()) { var dept = db.DEPT_TBL.FirstOrDefault(p => p.Dpt_id == id); if (dept != null) { var entry = db.Entry<DEPT_TBL>(model); if (entry.State.Equals(EntityState.Detached)) { db.DEPT_TBL.Attach(model); } entry.State = EntityState.Modified; } db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(FormCollection collection,DEPT_TBL model) { try { using (DMSDbEntities db = new DMSDbEntities()) { db.DEPT_TBL.Add(model); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }