public ActionResult SaveCompanyRoleMenu(string id, string ids = "") { string[] menuIds = id.Split(','); string[] info = ids.Split(','); int roleID = Convert.ToInt32(info[0]); int companyID = Convert.ToInt32(info[1]); var listToRemove = db.ROLE_MENU.AsEnumerable().Where(r => r.RoleId == roleID && r.CompanyId == companyID); db.ROLE_MENU.RemoveRange(listToRemove); db.SaveChanges(); for (int i = 0; i < menuIds.Length; i++) { int menuId = Convert.ToInt32(menuIds[i]); ROLE_MENU rm = new ROLE_MENU(); rm.RoleId = roleID; rm.MenuId = menuId; rm.IsActive = true; rm.CompanyId = companyID; db.ROLE_MENU.Add(rm); BaseUtil.SetSessionValue(UserInfo.IsCompanyAddUpdate.ToString(), "0"); db.SaveChanges(); BaseUtil.SetSessionValue(UserInfo.IsCompanyAddUpdate.ToString(), "1"); } ViewBag.role_id = id; return(Json(id)); //return View(); }
public ActionResult SaveRoleMenu(string id, int roleID) { string[] menuIds = id.Split(','); var listToRemove = db.ROLE_MENU.AsEnumerable().Where(r => r.RoleId == roleID); db.ROLE_MENU.RemoveRange(listToRemove); db.SaveChanges(); for (int i = 0; i < menuIds.Length; i++) { int menuId = Convert.ToInt32(menuIds[i]); ROLE_MENU rm = new ROLE_MENU(); rm.RoleId = roleID; rm.MenuId = menuId; rm.IsActive = true; db.ROLE_MENU.Add(rm); db.SaveChanges(); } ViewBag.role_id = id; return(Json(id)); //return View(); }