public int Save_Update_Delete_Role(Mst_Role role) { int id = 0; try { cmd = new SqlCommand("Role") { Connection = dbConnect.CreateConnection(), CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@RoleId", role.roleId); cmd.Parameters.AddWithValue("@RoleName", role.roleName); cmd.Parameters.AddWithValue("@IsActive", role.isActive); cmd.Parameters.AddWithValue("@Action", role.action); cmd.Connection.Open(); id = Convert.ToInt32(cmd.ExecuteScalar()); cmd.Connection.Close(); return(id); } catch (Exception ex) { return(id); } }
// GET: Mst_Role/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(HttpNotFound()); } Mst_Role mst_Role = new Mst_Role(); mst_Role = db.Mst_Roles.Find(id); if (mst_Role == null) { return(HttpNotFound()); } return(View(mst_Role)); }
public ActionResult Delete(int id) { try { // TODO: Add delete logic here Mst_Role mst_Role = db.Mst_Roles.Find(id); db.Mst_Roles.Remove(mst_Role); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateException) { ViewBag.message = "Delete failed. Please check if record is used by another table"; Mst_Role mst_Role2 = db.Mst_Roles.Find(id); return(View(mst_Role2)); } }
public ActionResult Edit(int id, Mst_Role mst_Role) { try { // TODO: Add update logic here if (ModelState.IsValid) { db.Entry(mst_Role).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Mst_Role mst_Role) { try { // TODO: Add insert logic here if (ModelState.IsValid) { db.Mst_Roles.Add(mst_Role); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }