public override void AddUsersToRoles(string[] usernames, string[] roleNames) { if (_App == null) { return; } foreach (string UN in usernames) { user mUser = UserSrv.GetByName(UN, _App.AppID); if (mUser != null) { string[] currentRoles = (from r in mUser.Roles where r.AppID == _App.AppID select r.name).ToArray(); foreach (string r in roleNames) { if (!currentRoles.Contains(r)) { role mRole = RoleSrv.GetByName(r, _App.AppID); if (mRole != null) { mUser.Roles.Add(mRole); } } } } } UserSrv.CommitChanges(); }
public ActionResult RoleInfo(RoleDTO dto) { if (ModelState.IsValid) { //添加 if (string.IsNullOrEmpty(dto.Id)) { string result = RoleSrv.InsertRole(dto); if (!string.IsNullOrEmpty(result) && result != "-2") { result = "1"; } return(Content(result, "text/plain")); } else { //编辑 RoleSrv.UpdateRole(dto); return(Content("1", "text/plain")); } } //获取ErrorMessage string errorMsg = ModelState.Values.First(x => x.Errors.Count > 0).Errors[0].ErrorMessage; return(Content(errorMsg, "text/plain")); }
public ActionResult PermissionsUpdate(string Id, string arrGrantStr) { string sSucceed = "1"; try { //角色ID。 string RoleId = Id; //肯定授权。 string sGrant = arrGrantStr; string[] arrGrant = null; if (sGrant.Length > 0) { arrGrant = sGrant.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); } else { arrGrant = new string[0]; } var arrDeny = new string[0]; RoleSrv.UpdatePermissions(RoleId, arrGrant, arrDeny); } catch (Exception ex) { sSucceed = "-1"; } return(Content(sSucceed)); }
public override bool RoleExists(string roleName) { if (_App == null) { return(false); } return(RoleSrv.GetByName(roleName, _App.AppID) != null); }
public override string[] GetUsersInRole(string roleName) { if (_App == null) { return(null); } role mRole = RoleSrv.GetByName(roleName, _App.AppID); if (mRole == null) { return(null); } return((from u in mRole.Users select u.username).ToArray()); }
public ActionResult MoveRole(string id, string newParentPKId) { string sSucceed = "1"; try { RoleSrv.MoveRole(id, newParentPKId); } catch (Exception ex) { sSucceed = "-1"; } return(Content(sSucceed)); }
public override string[] GetAllRoles() { if (_App == null) { return(null); } IList <role> lst = RoleSrv.GetAll(_App.AppID); if (lst == null || lst.Count == 0) { return new string[] { } } ; return((from r in lst select r.name).ToArray()); }
public ActionResult DelRole(string Id) { string sSucceed = "1"; try { RoleSrv.DeleteRole(Id); } catch (Exception ex) { sSucceed = "-1"; } return(Content(sSucceed)); }
public override void CreateRole(string roleName) { if (_App == null) { return; } role mRole = RoleSrv.GetByName(roleName, _App.AppID); if (mRole == null) { mRole = new role(); mRole.AppID = _App.AppID; mRole.name = roleName; RoleSrv.CreateNew(mRole); RoleSrv.CommitChanges(); } }
/// <summary> /// Removes the specified user names from the specified roles for the configured applicationName /// </summary> /// <param name="usernames"> A string array of user names to be removed from the specified roles.</param> /// <param name="roleNames">A string array of role names to remove the specified user names from.</param> public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { if (_App == null) { return; } string hql = "from user u where u.username in (:usernames)"; IList <user> UserList = UserSrv.GetbyHQuery(hql, new SQLParam("usernames", usernames.ToString())); string hql2 = "from role r where r.name in (:roleNames) AND r.AppID = :AppID"; IList <role> RoleList = RoleSrv.GetbyHQuery(hql2, new SQLParam("roleNames", roleNames.ToString()), new SQLParam("AppID", _App.AppID)); foreach (user u in UserList) { foreach (role r in RoleList) { if (u.Roles.Contains(r)) { u.Roles.Remove(r); } } } UserSrv.CommitChanges(); }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { if (_App == null) { return(false); } role mRole = RoleSrv.GetByName(roleName, _App.AppID); if (mRole == null) { return(false); } try { RoleSrv.Delete(mRole); RoleSrv.CommitChanges(); return(true); } catch (Exception ex) { throw ex; } }