Get the value of custom attributes in .NET CORE 2.0 aspnet-identity

0

I'm using Identity with aspnet core 2.0 and I needed to add the nuCPF attribute in the ApplicationUser table. In the controller I am getting the user data as follows:

[Controller: ClientController )

public ClienteController(UserManager<ApplicationUser> userManager)
{
    _userManager = userManager;
}

[HttpGet]
public ActionResult Index(int paginaAtual = 1, string filtro = "")
{
    var NomeUsuarioLogado = User.Identity.Name;
    var idUsuarioLogado = _userManager.GetUserId(HttpContext.User);

    xxxxx.... etc
}

The ApplicationUser class looks like this:

public class ApplicationUser
{
    public int Id { get; set; }
    public string UserName { get; set; }
    public string NormalizedUserName { get; set; }
    public string Email { get; set; }
    public string NormalizedEmail { get; set; }
    public bool EmailConfirmed { get; set; }
    public string PasswordHash { get; set; }
    public string PhoneNumber { get; set; }
    public bool PhoneNumberConfirmed { get; set; }
    public bool TwoFactorEnabled { get; set; }
    public string nuCPF { get; set; }
}

Doubt 1:

How can I get the value of the nuCPF field?

Doubt 2:

When I use 'userManager.GetUserId (user)' , is a select in the database made to get the id of the user?

    
asked by anonymous 22.01.2018 / 12:45

1 answer

0

To get all user information you should use:

var user = await _userManager.GetUserAsync(User);

Then only use user.NuCPF

And yes, he goes to the bank to get the information.

NOTE: Change the name of nuCPF to NuCPF . By convention, property names begin with capital letters.

    
01.03.2018 / 13:16