public bool Insert(RoleParam roleParam) { if (roleParam != null) { status = _roleRepository.Insert(roleParam); } return(status); }
public bool Update(int?Id, RoleParam roleParam) { if (Id != null && roleParam != null) { status = _roleRepository.Update(Id, roleParam); } return(status); }
public IActionResult RoleList(RoleParam param) { //排班接口 var role = this.GetInstance <IRoles>(); //查询所有角色 var result = role.GetRoleList(param.page_num, param.page_size)?.Result; return(Json(new ResponseModel(ResponseCode.Success, "查询成功!", result))); }
/// <summary> /// 获取角色详情 /// </summary> /// <param name="code">角色唯一标志</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Role> Detail( string code, CancellationToken cancellationToken = default) { var param = new RoleParam(code); await client.GetAccessToken(); var res = await client.Request <RoleResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }
//[SupportFilter] public JsonResult GetData(string id, RoleParam roleParam) { int total = 0; var queryData = SMROLETBService.LoadSearchEntities(roleParam); total = roleParam.TotalCount; var data = queryData.ToList().Select(m => new { ROLE_ID = m.ROLE_ID, ROLE_NAME = m.ROLE_NAME, CREATION_TIME = m.CREATION_TIME, REMARK = m.REMARK, STATUS = m.STATUS.GetStatusName() }); //构造成Json的格式传递 var result = new { total = total, rows = data }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <Role> Detail( string code, string _namespace = null, CancellationToken cancellationToken = default ) { var param = new RoleParam(code) { Namespace = _namespace }; var res = await client.Request <RoleResponse>(param.CreateRequest(), cancellationToken); return(res.Result); }
public bool Update(int?Id, RoleParam roleParam) { var result = 0; var Role = Get(Id); Role.Name = roleParam.Name; Role.UpdateDate = DateTimeOffset.UtcNow.LocalDateTime; result = myContext.SaveChanges(); if (result > 0) { status = true; } return(status); }
public bool Insert(RoleParam roleParam) { var result = 0; role.Name = roleParam.Name; role.CreateDate = DateTimeOffset.UtcNow.LocalDateTime; myContext.Roles.Add(role); result = myContext.SaveChanges(); if (result > 0) { status = true; } return(status); }
public async Task <ApiRequestResult> UpdateAsync([FromBody] RoleParam param) { try { var tRole = await _iTRoleRepository.GetAsync(c => c.Id == param.Id); tRole = param.EntityMap <TRole, RoleParam>(tRole); await _iTRoleRepository.UpdateAsync(tRole); return(ApiRequestResult.Success("修改成功")); } catch (Exception ex) { return(ApiRequestResult.Error(ex.Message)); } }
public async Task <string> QueryPagedAsync([FromQuery] RoleParam param) { var filter = param.SearchLambda <Role, RoleParam>(); var result = await _roleRepository.QueryPagedAsync(param.PageNum, param.PageSize, null, filter); var pageData = new PagedDto <Role> { Code = 200, Msg = "获取数据成功", Total = result.TotalResults, PageSize = param.PageSize, Data = result.Items.ToList() }; var json = pageData.ToString(); return(json); }
public ResultInfo Save(RoleParam param) { ResultInfo result = null; try { int roleId; var roleEntity = this.mapper.Map <RoleEntity>(param); if (roleEntity.Id == 0) { //insert this.dbContext.RoleRepository.Add(roleEntity); } else { //update this.dbContext.RoleRepository.Update(roleEntity); } roleId = roleEntity.Id; if (param.Resources != null) { this.dbContext.RoleResRepository.Remove(m => m.RoleId == roleId); foreach (var r in param.Resources) { this.dbContext.RoleResRepository.Add(new RoleResourceRelationEntity() { ResourceId = r.Id, Status = r.Status, RoleId = roleId }); } } this.dbContext.SaveChanges(); result = new ResultInfo(); } catch (Exception ex) { result = new ResultExceptionInfo() { Exception = ex }; } return(result); }
/// <summary> /// 多条件搜索角色信息 /// </summary> /// <param name="roleParam">角色查询参数实体</param> /// <returns></returns> public IQueryable <SMROLETB> LoadSearchEntities(RoleParam roleParam) { Expression <Func <SMROLETB, bool> > whereLambda = PredicateBuilder.True <SMROLETB>(); if (!string.IsNullOrEmpty(roleParam.ROLE_NAME)) { whereLambda = whereLambda.And(u => u.ROLE_NAME.Contains(roleParam.ROLE_NAME)); } if (!string.IsNullOrEmpty(roleParam.STATUS)) { whereLambda = whereLambda.And(u => u.STATUS == roleParam.STATUS); } int count = 0; IQueryable <SMROLETB> queryData = null; if (!string.IsNullOrEmpty(roleParam.order) && !string.IsNullOrEmpty(roleParam.sort)) { bool isAsc = roleParam.order == "asc" ? true : false; queryData = LoadPageEntities <SMROLETB>(roleParam.page, roleParam.rows, out count, whereLambda, roleParam.sort, isAsc); } else { queryData = LoadPageEntities <SMROLETB>(roleParam.page, roleParam.rows, out count, whereLambda, roleParam.sort, null); } roleParam.TotalCount = count; foreach (var item in queryData) { if (item.SMUSERTB != null) { item.SysPersonId = string.Empty; foreach (var it in item.SMUSERTB2) { item.SysPersonId += it.User.USER_NAME + ' '; } } } return(queryData); }
public async Task <ApiRequestResult> AddAsync([FromBody] RoleParam param) { try { var add = new TRole { RoleName = param.RoleName, ParentId = param.ParentId, Description = param.Description, }; await _iTRoleRepository.AddAsync(add); //_unitOfWork.SaveChanges(); return(ApiRequestResult.Success("添加成功")); } catch (Exception ex) { return(ApiRequestResult.Error(ex.Message)); } }
// PUT: api/Role/5 public void Put(int id, RoleParam roleParam) { _roleService.Update(id, roleParam); }
// POST: api/Role public void Post(RoleParam roleParam) { _roleService.Insert(roleParam); }
public ResultInfo PostSave([FromBody] RoleParam param) { return(this.roleService.Save(param)); }
public bool ChangeRole(Guid transactionid, AdminInfo admin, RoleInfo role, out string strJsonResult) { bool result = true; strJsonResult = string.Empty; ErrorCodeInfo error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"AdminID:{admin.UserID}"; paramstr += $"||AdminAccount:{admin.UserAccount}"; paramstr += $"||RoleID:{role.RoleID}"; paramstr += $"||RoleName:{role.RoleName}"; paramstr += $"||ControlLimit:{role.ControlLimit.ToString()}"; paramstr += $"||ControlLimitID:{role.ControlLimitID}"; paramstr += $"||Members:"; for (int i = 0; i < role.UserList.Count; i++) { paramstr += role.UserList[i].UserID + ","; } string funname = "ChangeRole"; try { do { error = role.ChangeCheckProp(); if (error.Code != ErrorCode.None) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } RoleInfo oldrole = new RoleInfo(); RoleDBProvider provider = new RoleDBProvider(); if (!provider.GetRoleInfo(transactionid, admin, role.RoleID, out oldrole, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } if (oldrole.IsDefault == 1 && role.UserList.Count == 0) { error.Code = ErrorCode.MustHaveMember; strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } DirectoryEntry entry = new DirectoryEntry(); CommonProvider commonProvider = new CommonProvider(); List <ControlLimitOuInfo> controlLimitOus = new List <ControlLimitOuInfo>(); List <string> controlOUdistinguishedNames = new List <string>(); for (int i = 0; i < role.ControlLimitOuList.Count; i++) { if (!commonProvider.GetADEntryByGuid(role.ControlLimitOuList[i].OuID, out entry, out message)) { error.Code = ErrorCode.SearchADDataError; strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("AddRole调用GetADEntryByGuid异常", paramstr, message, transactionid); result = false; break; } string OUdistinguishedName = Convert.ToString(entry.Properties["distinguishedName"].Value); if (!controlOUdistinguishedNames.Contains(OUdistinguishedName)) { controlOUdistinguishedNames.Add(OUdistinguishedName); ControlLimitOuInfo controlLimitOu = new ControlLimitOuInfo(); controlLimitOu.OuID = role.ControlLimitOuList[i].OuID; controlLimitOu.OUdistinguishedName = OUdistinguishedName; controlLimitOus.Add(controlLimitOu); } } if (result) { if (controlOUdistinguishedNames.Count == 0) { error.Code = ErrorCode.ControlOUPathNotEmpty; strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("ChangeRole异常", paramstr, error.Info, transactionid); result = false; break; } if (!CheckControlOUdistinguishedNames(transactionid, controlOUdistinguishedNames, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("ChangeRole异常", paramstr, error.Info, transactionid); result = false; break; } string members = string.Empty; for (int i = 0; i < role.UserList.Count; i++) { if (!commonProvider.GetADEntryByGuid(role.UserList[i].UserID, out entry, out message)) { LoggerHelper.Error("ChangeRole调用GetADEntryByGuid异常", paramstr, message, transactionid); continue; } string DisplayName = entry.Properties["cn"].Value == null ? "" : Convert.ToString(entry.Properties["cn"].Value); string UserAccount = entry.Properties["userPrincipalName"].Value == null ? "" : Convert.ToString(entry.Properties["userPrincipalName"].Value); AdminInfo userRole = new AdminInfo(); if (provider.GetUserRole(transactionid, role.UserList[i].UserID, ref userRole, out error)) { if (userRole.RoleID != role.RoleID) { error.Code = ErrorCode.UserHaveRole; string errormessage = DisplayName + "(" + UserAccount + ") 已存在角色"; strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), errormessage); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("ChangeRole调用GetADEntryByGuid异常", paramstr, message, transactionid); result = false; break; } } members += DisplayName + "(" + UserAccount + "),"; } members = string.IsNullOrEmpty(members) ? string.Empty : members.Remove(members.LastIndexOf(','), 1); if (result) { //检查权限 List <RoleParam> roleParams = new List <RoleParam>(); for (int i = 0; i < role.RoleList.Count; i++) { foreach (RoleParam param in role.RoleList[i].RoleParamList) { RoleParam roleParam = new RoleParam(); if (provider.GetRoleParam(transactionid, param.ParamID, out roleParam, out error)) { roleParams.Add(roleParam); } } } var query = from r in roleParams where r.ParamCode.Equals("SameLevelOu") select r; if (query.Any()) { if (role.SameLevelOuList.Count == 0) { error.Code = ErrorCode.MustHaveSameLevelOuPath; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; break; } } if (!provider.ChangeRole(transactionid, admin, role, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } for (int i = 0; i < role.RoleList.Count; i++) { foreach (RoleParam param in role.RoleList[i].RoleParamList) { if (!provider.AddRoleModuleParam(transactionid, role.RoleID, param, out error)) { continue; } } } for (int i = 0; i < role.UserList.Count; i++) { if (!provider.AddRoleMembers(transactionid, role.RoleID, role.UserList[i], out error)) { continue; } } for (int i = 0; i < role.SameLevelOuList.Count; i++) { if (!provider.AddSameLevelOu(transactionid, role.RoleID, role.SameLevelOuList[i], out error)) { continue; } } for (int i = 0; i < controlLimitOus.Count; i++) { if (!provider.AddControlLimitOu(transactionid, role.RoleID, controlLimitOus[i], out error)) { continue; } } error.Code = ErrorCode.None; string json = JsonConvert.SerializeObject(role); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid); strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info, json); #region 操作日志 LogInfo operateLog = new LogInfo(); operateLog.AdminID = admin.UserID; operateLog.AdminAccount = admin.UserAccount; operateLog.RoleID = admin.RoleID; operateLog.ClientIP = _clientip; operateLog.OperateResult = true; operateLog.OperateType = "修改角色"; operateLog.OperateLog = $"{admin.UserAccount}于{DateTime.Now}修改角色。" + $"原角色名称:{oldrole.RoleName},现角色名称{role.RoleName};" + $"原管理范围:{oldrole.ControlLimitPath},现管理范围:{role.ControlLimitPath};" + $"现成员:{members}"; LogManager.AddOperateLog(transactionid, operateLog); #endregion result = true; } } } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("RoleManager调用ChangeRole异常", paramstr, ex.ToString(), transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; } return(result); }