public ActionResult Create(USER_TBL userModel,FormCollection collection) { try { userModel.GNDR = (collection["GNDR"] == "Male") ? 1 : 2; using (DMSDbEntities db = new DMSDbEntities()) { db.USER_TBL.Add(userModel); db.SaveChanges(); return RedirectToAction("Index",db.USER_TBL.ToList()); } } catch { return View(userModel); } }
public ActionResult Edit(USER_TBL userModel, FormCollection collection) { try { userModel.GNDR = (collection["GNDR"] == "Male") ? 1 : 2; using (DMSDbEntities db = new DMSDbEntities()) { var entry = db.Entry<USER_TBL>(userModel); if (entry.State.Equals(EntityState.Detached)) { db.USER_TBL.Attach(userModel); } entry.State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index",db.USER_TBL.ToList()); } } catch { return View(); } }
public ActionResult Delete(USER_TBL userModel) { try { using (DMSDbEntities db = new DMSDbEntities()) { var entry = db.Entry<USER_TBL>(userModel); entry.State = EntityState.Deleted; db.USER_TBL.ToList().RemoveAll(p => p.USER_ID == userModel.USER_ID); db.SaveChanges(); return RedirectToAction("Index",db.USER_TBL.ToList()); } } catch { return View(); } }