/// <summary> /// /// </summary> /// <param name="primaryKey"></param> /// <param name="lazy"></param> /// <returns></returns> z public PowerRole Load(string primaryKey, bool lazy) { string sqlstring = PrepareSQL("Manager.PowerRoleManager.LoadByPrimaryKey", new string[] { primaryKey }); if (sqlstring == string.Empty) { return(null); } try { this.ExecQuery(sqlstring); if (this.Reader.Read()) { PowerRole role = new PowerRole(); PrepareData(role); if (!lazy) { SelectPowerRoleDetail(role); } return(role); } } catch (Exception ex) { this.ErrCode = ex.Message; this.Err = ex.Message; } return(null); }
/// <summary> /// 验证角色 /// </summary> /// <param name=""></param> /// <returns></returns> public Result CheckRole(PowerRole model) { if (string.IsNullOrWhiteSpace(model.Name)) { return(Result.Fail("名称不能为空")); } if (model.Elements.Count() <= 0) { return(Result.Fail("请勾选对应的权限")); } if (model.Id <= 0) { if (_roleBusiness.Exist(p => p.Name == model.Name && p.Status == NomalStatus.Valid)) { return(Result.Fail("名称已存在")); } } else { if (_roleBusiness.Exist(p => p.Name == model.Name && p.Status == NomalStatus.Valid && p.Id != model.Id)) { return(Result.Fail("名称已存在")); } } return(Result.Success()); }
public int DeletePowerRole(PowerRole info) { if (info == null) { return(-1); } return(DeletePowerRole(info.RoleCode)); }
public void SelectPowerRoleDetail(PowerRole role, bool must) { if (role != null) { if (must) { role.RolePowerDetails = SelectPowerRoleDetail(role.RoleCode); } else if (role.RolePowerDetails != null) { role.RolePowerDetails = SelectPowerRoleDetail(role.RoleCode); } } }
private void PrepareData(PowerRole role) { try { role.RoleCode = this.Reader[0].ToString(); role.RoleName = this.Reader[1].ToString(); role.RoleMeanint = this.Reader[2].ToString(); role.RoleType = this.Reader[3].ToString(); role.Mark = this.Reader[4].ToString(); role.ID = role.RoleCode; role.Name = role.RoleName; } catch (Exception ex) { this.ErrCode = ex.Message; this.Err = ex.Message; throw ex; } }
/// <summary> /// 加载所有Role的信息,不包括详细信息。 /// </summary> /// <returns></returns> public ArrayList LoadAll() { string sqlstring = PrepareSQL("Manager.PowerRoleManager.LoadAll", null); if (sqlstring == string.Empty) { return(null); } RoleTypeManager typeMgr = new RoleTypeManager(); ArrayList roles = new ArrayList(); try { this.ExecQuery(sqlstring); while (this.Reader.Read()) { PowerRole role = new PowerRole(); //进行附值 PrepareData(role); RoleType roleType = typeMgr.LoadByPrimaryKey(role.RoleType); if (roleType != null) { role.Memo = roleType.TypeName; } roles.Add(role); } } catch (Exception ex) { this.ErrCode = ex.Message; this.Err = ex.Message; roles.Clear(); } return(roles); }
/// <summary> /// /// </summary> /// <param name="role"></param> /// <returns></returns> public int InsertPowerRole(PowerRole role) { string strSql = ""; if (this.Sql.GetSql("Manager.PowerRoleManager.InsertPowerRole", ref strSql) == -1) { return(-1); } try { // strSql = string.Format(strSql,info.RoleCode, info.RoleName, info.RoleMeanint, info.Class2Code, info.Class2Name, info.Class3Code, info.Class3Name, info.Mark, this.Operator.ID,this.GetSysDateTime()); strSql = string.Format(strSql, role.RoleName, role.RoleMeanint, role.RoleType, this.Operator.ID, this.Operator.Name, role.Mark); } catch (Exception ex) { this.Err = ex.Message; this.ErrCode = ex.Message; return(-1); } return(this.ExecNoQuery(strSql)); }
/// <summary> /// 加载Role的明细。如果role.RolePowerDetails为null,则加载,否则不加载 /// </summary> /// <param name="role"></param> public void SelectPowerRoleDetail(PowerRole role) { SelectPowerRoleDetail(role, false); }
public Result AddOrEditRole(PowerRole model) { var result = CheckRole(model); if (!result.Succeed) { return(result); } model.Status = NomalStatus.Valid; try { using (TransactionScope ts = new TransactionScope()) { //新增 if (model.Id <= 0) { _roleBusiness.Add(model); } //先删除角色对应的模块和模块元素 _relevanceBusiness.Delete(p => p.FirstId == model.Id); //模块数据去重 List <int> lsDistinctModule = model.Elements.Select(t => t.ModuleId).Distinct().ToList(); if (lsDistinctModule.Count() == 0) { return(Result.Fail("未获取到录入的数据")); } //获取 模块数据 var dbModule = _moduleBusiness.Query(p => p.Status == NomalStatus.Valid); //多对多关系集中映射表 var lsRelevance = new List <PowerRelevance>(); //保存对应的模块 var lsModule = new List <PowerModule>(); //循环并拿去 模块的所有父节点 foreach (var item in lsDistinctModule) { var nodeModule = GetFatherList(dbModule, item); lsModule.AddRange(nodeModule); } //拿到所有模块 去重 List <int> distinctModule = lsModule.Select(t => t.Id).Distinct().ToList(); foreach (var item in distinctModule) { lsRelevance.Add(new PowerRelevance() { Id = 0, FirstId = model.Id, SecondId = item, Identifiers = PowerIdentifiers.RoleByModule, Remarks = PowerIdentifiers.RoleByModule.GetDescription() }); } if (lsDistinctModule.Count() == 0) { return(Result.Fail("未获取到录入的数据")); } //角色对应的模块元素 foreach (var item in model.Elements) { lsRelevance.Add(new PowerRelevance() { Id = 0, FirstId = model.Id, SecondId = item.Id, Identifiers = PowerIdentifiers.RoleByElement, Remarks = PowerIdentifiers.RoleByElement.GetDescription() }); } _roleBusiness.Update(model); _relevanceBusiness.AddRange(lsRelevance); ts.Complete(); return(Result.Success()); } } catch (Exception ex) { return(Result.Fail("操作失败:" + ex.Message)); } }
public Result EditRole([FromForm] PowerRole model) { return(_wrappers.AddOrEditRole(model)); }