public ActionResult UserRole(FormCollection formCollection) { string userid = formCollection["userid"]; var roles = DaoRole.FindList(); var exists = DaoUserole.FindList("", "USER_ID", userid); List <SYS_USEROLE> addroleauths = new List <SYS_USEROLE>(), delroleauths = new List <SYS_USEROLE>(); if (roles != null) { foreach (var role in roles) { var formitem = formCollection["chkChecked" + role.ROLE_ID]; if (null != formitem) { if (formitem.Contains("true")) { if (exists.All(obj => obj.ROLE_ID != role.ROLE_ID)) //原权限中不存在 { addroleauths.Add(new SYS_USEROLE { USER_ID = userid, ROLE_ID = role.ROLE_ID, CREATE_DTIME = DateTime.Now, CREATE_ID = UserState.UserID }); } } else { var e = exists.FirstOrDefault(obj => obj.ROLE_ID == role.ROLE_ID); if (null != e) { delroleauths.Add(e); } } } } } if (addroleauths.Count > 0) { DaoUserole.AddObject(addroleauths); } if (delroleauths.Count > 0) { DaoUserole.DeleteObject(delroleauths); } Alter("修改成功!", AlterTypeEnum.Success, true, true); GetViewData(userid); return(View("UserRole", DaoUserole.FindList("USER_ID", "USER_ID", userid))); }
private void GetViewData(string id) { TempData["user"] = DaoUser.GetEntity("USER_ID", id); TempData["roles"] = DaoRole.FindList("ROLE_ID"); }