示例#1
0
        public async Task <bool> RemoveRoleToUserAsync(UpdateUserRoleModelRq model)
        {
            try
            {
                var user = await _userManagement.FindByIdAsync(model.UserId.ToString());

                if (user == null)
                {
                    return(false);
                }
                var roles = await _userManagement.GetRolesAsync(user);

                if (roles.Count > 1)
                {
                    var rs = await _userManagement.RemoveFromRoleAsync(user, model.RoleName);

                    if (rs.Succeeded)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#2
0
        public async Task <IActionResult> RemoveRoleToUser(int userId, string roleName)
        {
            UpdateUserRoleModelRq model = new UpdateUserRoleModelRq()
            {
                UserId   = userId,
                RoleName = roleName
            };

            return(OkValueObject(await _userService.RemoveRoleToUserAsync(model)));
        }
示例#3
0
 public async Task <IActionResult> AddRoleToUser([FromBody] UpdateUserRoleModelRq model)
 {
     if (!ModelState.IsValid)
     {
         Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
         foreach (var entry in ModelState.Values)
         {
             foreach (var error in entry.Errors)
             {
                 modelErrors.Add(error);
             }
         }
         return(BadRequest(modelErrors));
     }
     return(OkValueObject(await _userService.AddRoleToUserAsync(model)));
 }
示例#4
0
        public async Task <bool> AddRoleToUserAsync(UpdateUserRoleModelRq model)
        {
            try
            {
                var user = await _userManagement.FindByIdAsync(model.UserId.ToString());

                if (user == null)
                {
                    return(false);
                }
                var rs = await _userManagement.AddToRoleAsync(user, model.RoleName);

                if (rs.Succeeded)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }