public async Task <ResponseModel> DeleteRoleClaim(RoleClaimAssignModel roleClaim) { try { var appRole = await _roleManager.FindByIdAsync(roleClaim.RoleId); var res = await _roleManager.RemoveClaimAsync(appRole, new Claim(roleClaim.ClaimType, roleClaim.ClaimValue)); if (res.Succeeded) { return new ResponseModel { Status = HttpStatusCode.OK, Success = "Claim has been delete" } } ; else { return new ResponseModel { Status = HttpStatusCode.BadRequest, Errors = res.Errors.Select(x => x.Code + "-" + x.Description) } }; } catch (System.Exception ex) { return(new ResponseModel { Status = HttpStatusCode.InternalServerError, Errors = new[] { "Exception:" + ex.Message } }); } }
public async Task <IActionResult> ClaimAssignToRole([FromBody] RoleClaimAssignModel objInput) { //var IsValidClaim = HttpContext.ValidatePermission("2"); //if (!IsValidClaim) // return Unauthorized("you don't have permission"); var blRole = await _userManager.RoleClaimAssign(objInput); if (blRole.Status == HttpStatusCode.OK) { return(Ok(blRole)); } else { return(BadRequest(blRole)); } }
public async Task <ResponseModel> RoleClaimAssign(RoleClaimAssignModel roleClaim) { try { var role = await _roleManager.FindByIdAsync(roleClaim.RoleId); if (role == null) { return new ResponseModel { Status = HttpStatusCode.BadRequest, Errors = new[] { "Role not found" } } } ; var res = await _roleManager.AddClaimAsync(role, new System.Security.Claims.Claim(roleClaim.ClaimType, roleClaim.ClaimValue)); if (res.Succeeded) { return new ResponseModel { Status = HttpStatusCode.OK, Success = "Claim has assigned to role" } } ; else { return new ResponseModel { Status = HttpStatusCode.BadRequest, Errors = res.Errors.Select(x => x.Code + "-" + x.Description) } }; } catch (System.Exception ex) { return(new ResponseModel { Status = HttpStatusCode.InternalServerError, Errors = new[] { "Exception:" + ex.Message } }); } }