public GetsResult <RoleDetails> Gets(RoleParams param) { var result = GetDefault <GetsResult <RoleDetails> >(); var query = DbEntities.UserRoles.OrderByDescending(x => x.ID).AsQueryable(); if (!string.IsNullOrWhiteSpace(param.Name)) { query = query.Where(x => x.RoleName.Contains(param.Name)); } if (param.UserId > 0) { query = query.Where(x => x.UserToUserRoles.Any(z => z.UserId == param.UserId)); } result.Total = query.Count(); result.Data = query.Skip((param.Current - 1) * param.Size).Take(param.Size).Select(x => new RoleDetails() { Id = x.ID, Name = x.RoleName, Funs = x.UserPermissions.Select(f => new IdWithName() { Id = f.UserFunctionality.Id, Name = f.UserFunctionality.Name }).ToList() }).ToList(); return(result); }
/// <summary> /// 新增員工身分資料 /// </summary> public bool InsertEmployeeRoleData(RoleParams param) { InsertResult insResult = new InsertResult() { IsSuccess = false }; using (EmployeeAuthorityDataAccess empAuthDao = new EmployeeAuthorityDataAccess()) { EmployeeRole entity = new EmployeeRole() { RoleName = param.RoleName, RoleDisplayName = param.RoleDisplayName, SortNo = param.SortNo, PostAccount = param.PostAccount, PostDate = DateTime.Now }; insResult = empAuthDao.InsertEmployeeRoleData(entity, param.CopyPrivilegeFromRoleName); dbErrMsg = empAuthDao.GetErrMsg(); if (insResult.IsSuccess) { param.RoleId = entity.RoleId; } else if (empAuthDao.GetSqlErrNumber() == 50000 && empAuthDao.GetSqlErrState() == 2) { param.HasRoleBeenUsed = true; } } return(insResult.IsSuccess); }
/// <summary> /// 刪除員工身分 /// </summary> public bool DeleteEmployeeRoleData(RoleParams param) { bool result = false; using (EmployeeAuthorityDataAccess empAuthDao = new EmployeeAuthorityDataAccess()) { result = empAuthDao.DeleteEmployeeRoleData(param.RoleId); dbErrMsg = empAuthDao.GetErrMsg(); if (!result && empAuthDao.GetSqlErrNumber() == 50000 && empAuthDao.GetSqlErrState() == 2) { param.IsThereAccountsOfRole = true; } } return(result); }
public GetsResult<RoleDetails> Gets(RoleParams param) { var result = GetDefault<GetsResult<RoleDetails>>(); var query = DbEntities.UserRoles.OrderByDescending(x => x.ID).AsQueryable(); if (!string.IsNullOrWhiteSpace(param.Name)) query = query.Where(x => x.RoleName.Contains(param.Name)); if (param.UserId > 0) query = query.Where(x => x.UserToUserRoles.Any(z => z.UserId == param.UserId)); result.Total = query.Count(); result.Data = query.Skip((param.Current - 1) * param.Size).Take(param.Size).Select(x => new RoleDetails() { Id = x.ID, Name = x.RoleName, Funs = x.UserPermissions.Select(f => new IdWithName() { Id = f.UserFunctionality.Id, Name = f.UserFunctionality.Name }).ToList() }).ToList(); return result; }
protected void rptRoles_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Del": string[] args = e.CommandArgument.ToString().Split(','); int roleId = Convert.ToInt32(args[0]); string roleName = args[1]; RoleParams param = new RoleParams() { RoleId = roleId }; bool result = empAuth.DeleteEmployeeRoleData(param); //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = c.GetEmpAccount(), Description = string.Format(".刪除身分/Delete role .代碼/id[{0}] 名稱/name[{1}] 結果/result[{2}]", roleId, roleName, result), IP = c.GetClientIP() }); // log to file c.LoggerOfUI.InfoFormat("{0} deletes {1}, result: {2}", c.GetEmpAccount(), "role-" + roleId.ToString() + "-" + roleName, result); if (result) { DisplayRoles(); } else { if (param.IsThereAccountsOfRole) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_ThereIsAccountOfRole); } else { Master.ShowErrorMsg(Resources.Lang.ErrMsg_DeleteRoleFailed); } } break; } }
public async Task <IActionResult> GetAllRoles([FromQuery] RoleParams roleParams) { var result = await rolesManagementService.GetAppRoles(roleParams); var metadata = new { result.TotalCount, result.PageSize, result.CurrentPage, result.TotalPages, result.HasNext, result.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(result)); }
/// <summary> /// 更新員工身分資料 /// </summary> public bool UpdateEmployeeRoleData(RoleParams param) { bool result = false; using (EmployeeAuthorityDataAccess empAuthDao = new EmployeeAuthorityDataAccess()) { EmployeeRole entity = empAuthDao.GetEmptyEntity <EmployeeRole>(new EmployeeRoleRequiredPropValues() { RoleId = param.RoleId, RoleName = "" }); entity.RoleDisplayName = param.RoleDisplayName; entity.SortNo = param.SortNo; entity.MdfAccount = param.PostAccount; entity.MdfDate = DateTime.Now; result = empAuthDao.Update(); dbErrMsg = empAuthDao.GetErrMsg(); } return(result); }
public async Task <IActionResult> RemoveRole([FromBody] RoleParams data) { var roleExists = await _roleManager.RoleExistsAsync(data.roleName); var user = await _userManager.FindByIdAsync(data.userId); if (roleExists) { var roleResult = await _userManager.RemoveFromRoleAsync(user, data.roleName); if (roleResult.Succeeded) { return(Ok()); } else { return(BadRequest()); } } else { return(BadRequest()); } }
protected void btnSave_Click(object sender, EventArgs e) { if (!IsValid) { return; } try { txtRoleName.Text = txtRoleName.Text.Trim(); txtRoleDisplayName.Text = txtRoleDisplayName.Text.Trim(); RoleParams param = new RoleParams() { RoleName = txtRoleName.Text, RoleDisplayName = txtRoleDisplayName.Text, SortNo = Convert.ToInt32(txtSortNo.Text.Trim()), PostAccount = c.GetEmpAccount() }; bool result = false; if (c.qsAct == ConfigFormAction.add) { if (ddlCopyPrivilegeFrom.SelectedIndex > 0) { param.CopyPrivilegeFromRoleName = ddlCopyPrivilegeFrom.SelectedValue; } result = empAuth.InsertEmployeeRoleData(param); if (!result) { if (param.HasRoleBeenUsed) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_RoleNameHasBeenUsed); } else { Master.ShowErrorMsg(Resources.Lang.ErrMsg_AddFailed); } } } else if (c.qsAct == ConfigFormAction.edit) { param.RoleId = c.qsRoleId; result = empAuth.UpdateEmployeeRoleData(param); if (!result) { Master.ShowErrorMsg(Resources.Lang.ErrMsg_UpdateFailed); } } if (result) { ClientScript.RegisterStartupScript(this.GetType(), "", StringUtility.GetNoticeOpenerJs("Config"), true); } //新增後端操作記錄 empAuth.InsertBackEndLogData(new BackEndLogData() { EmpAccount = c.GetEmpAccount(), Description = string.Format(".{0} .儲存身分/Save role[{1}] RoleId[{2}] 結果/result[{3}]", Title, txtRoleName.Text, param.RoleId, result), IP = c.GetClientIP() }); } catch (Exception ex) { c.LoggerOfUI.Error("", ex); Master.ShowErrorMsg(ex.Message); } }
public async Task <PagedList <IdentityRole> > GetAppRoles(RoleParams roleParams) { var roles = await roleManager.Roles.ToListAsync(); return(new PagedList <IdentityRole>(roles, roles.Count, roleParams.PageNumber, roleParams.PageSize)); }
public ResultBase Gets([FromUri] RoleParams param) { return(Service.Gets(param)); }