Nabi.M
Nabi.M

Reputation: 77

How do i sets GetRolesAsync to string model?

I Have string model in my viewmodel i want to convert GetRolesAsync to string.

var string = await _userManager.GetRolesAsync(item);

> 'string' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'string'

Upvotes: 0

Views: 663

Answers (2)

Mahmoud Bayoush
Mahmoud Bayoush

Reputation: 59

var user = await _userManager.Users.Where(x => x.Id == request.UserId).FirstOrDefaultAsync();

            if (user != null)
            {
                Task<IList<string>> roles = _userManager.GetRolesAsync(user);
                var returnUser = _mapper.Map<AspNetUser, AspNetUserDto>(user);
                if (returnUser != null)
                {
                    if (roles != null && roles.Result != null)
                        returnUser.Roles = roles.Result.ToList();

                    return returnUser;
                }
            }

Upvotes: 0

Nabi.M
Nabi.M

Reputation: 77

I found the answer

var rolename = await _userManager.GetRolesAsync(model);
        user1.RoleName = rolename[0].ToString();

Its works fine for me.

Upvotes: 0

Related Questions