/// <summary> /// 保存用户角色 幂等操作 /// </summary> /// <param name="roleCodes">角色代码</param> /// <param name="userId"></param> public void SaveUserInRoleByCodes(string[] roleCodes, int userId) { if (userId == 0 || userId == 0) { throw new UIValidateException("用户ID 和角色Code不能为0"); } using (var db = DbAccess.DbFrameworkContext.Create()) { //转化为ROLEID var roleIds = db.T_QWF_Role.Where(w => roleCodes.Contains(w.RoleCode) && w.IsDelete == 0).Select(s => s.RoleId).ToList(); //删除不存在的角色 db.T_QWF_UserInRole.Where(w => !roleIds.Contains(w.RoleId) && w.UserId == userId).ToList().ForEach(item => { db.T_QWF_UserInRole.Remove(item); }); //逐个添加 foreach (var roleId in roleIds) { var roleHelper = new BLL.RoleHelper(db, this.svrUser); roleHelper.AddUserInRoles(roleId, userId); } db.SaveChanges(); } }
public void AddUserInRole(int roleId, string[] userIds) { if (roleId == 0) { throw new UIValidateException("角色ID=0"); } using (var db = DbAccess.DbFrameworkContext.Create()) { var roleHelper = new BLL.RoleHelper(db, this.svrUser); var role = roleHelper.GetRoleById(roleId); if (role == null) { throw new UIValidateException(string.Format("角色不存在或删除,ID={0}", roleId)); } foreach (string userId in userIds) { roleHelper.AddUserInRoles(role.GetRoleId(), userId.SafeConvert().ToInt32(0)); } db.SaveChanges(); } }
public int CreateRoleGroup(SvrModels.SvrRoleGroupInfo svrModel) { using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); var role = helper.CreateRoleGroup(svrModel); db.SaveChanges(); return(role.GetGroupId()); } }
public bool DeleteUserInRoles(string[] ids) { using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); foreach (string id in ids) { helper.DeleteUserInRoleId(id.SafeConvert().ToInt32()); } db.SaveChanges(); return(true); } }
public bool DeleteRoleGroup(int groupId) { using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); var role = helper.GetRoleGroupById(groupId); if (role == null) { throw new QWF.Framework.GlobalException.UIValidateException(string.Format("角色组不存在或已删除,GroupId={0}", groupId)); } role.Deleted(); db.SaveChanges(); return(true); } }
public bool UpdateRoleGroup(SvrModels.SvrRoleGroupInfo svrModel) { using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); var role = helper.GetRoleGroupById(svrModel.GroupId); if (role == null) { throw new QWF.Framework.GlobalException.UIValidateException(string.Format("角色组不存在GroupId={0}", svrModel.GroupId)); } role.UpdateRoleGroup(svrModel); db.SaveChanges(); return(true); } }
public bool DeleteRole(int roleId) { using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); var role = helper.GetRoleById(roleId); if (role == null) { throw new UIValidateException(string.Format("角色不存或已删除,RoleId={0}", roleId)); } role.Deleted(); db.SaveChanges(); return(true); } }
public int CreateRole(SvrModels.SvrRoleInfo svrModel) { //生产角色编号 if (svrModel.RoleCode.StrValidatorHelper().StrIsNullOrEmpty()) { var common = new SeqServices(this.svrUser); svrModel.RoleCode = common.CreateNewSeqNo("system.rolecode"); } using (var db = DbAccess.DbFrameworkContext.Create()) { var helper = new BLL.RoleHelper(db, this.svrUser); var role = helper.CreateRole(svrModel); db.SaveChanges(); return(role.GetRoleId()); } }
/// <summary> /// 新增用户角色 /// </summary> /// <param name="roleId">角色ID</param> /// <param name="userId"></param> public void AddUserInRoleById(int roleId, int userId) { if (userId == 0 || roleId == 0) { throw new UIValidateException("用户ID 和角色ID不能为0"); } using (var db = DbAccess.DbFrameworkContext.Create()) { var roleHelper = new BLL.RoleHelper(db, this.svrUser); var role = roleHelper.GetRoleById(roleId); if (role == null) { throw new UIValidateException(string.Format("角色不存在或删除,ID={0}", roleId)); } roleHelper.AddUserInRoles(role.GetRoleId(), userId); db.SaveChanges(); } }
public RoleGroup(DbAccess.T_QWF_RoleGroup dbModel, RoleHelper helper) { this.dbModel = dbModel; this.helper = helper; }
public UserInRole(DbAccess.T_QWF_UserInRole dbModel, RoleHelper helper) { this.dbModel = dbModel; this.helper = helper; }