Beispiel #1
0
        public async Task <ResponseModel> UserClaimAssign(UserClaimAssignModel userClaim)
        {
            try
            {
                var appUser = await _userManager.FindByIdAsync(userClaim.UserId);

                var res = await _userManager.AddClaimAsync(appUser, new System.Security.Claims.Claim(userClaim.ClaimType, userClaim.ClaimValue));

                if (res.Succeeded)
                {
                    return new ResponseModel {
                               Status = HttpStatusCode.OK, Success = "claim has assigned to user"
                    }
                }
                ;
                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 }
                });
            }
        }
Beispiel #2
0
        public async Task <ResponseModel> DeleteUserClaim(UserClaimAssignModel userClaim)
        {
            try
            {
                var appUser = await _userManager.FindByIdAsync(userClaim.UserId);

                var res = await _userManager.RemoveClaimAsync(appUser, new Claim(userClaim.ClaimType, userClaim.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 }
                });
            }
            throw new NotImplementedException();
        }
        public async Task <IActionResult> ClaimAssignToUser([FromBody] UserClaimAssignModel objInput)
        {
            //var IsValidClaim = HttpContext.ValidatePermission("2");
            //if (!IsValidClaim)
            //    return Unauthorized("you don't have permission");


            var blUser = await _userManager.UserClaimAssign(objInput);

            if (blUser.Status == HttpStatusCode.OK)
            {
                return(Ok(blUser));
            }
            else
            {
                return(BadRequest(blUser));
            }
        }