Creating Models that derive IdentityUser or use the AspNetUsers table

3

I am developing management software for my fitness club.

I have students, teachers and system users.

I installed identity.

I created a model named Aluno that inherits from IdentityUser

  public class Aluno : IdentityUser
    {

        public int AlunoId { get; set; }
        public string Nome { get; set; }
        //etc
}

Now I would create the teachers, so I thought

Professor: IdentityUser

But would not it be better to use the table itself created by identity AspNetUsers ?

I'm a bit confused, because then I'll put some "student", "teacher", "admin", "operator", etc. roles that will be the access level in the system administrative panel. >

How I would then to add Students. But it made a mistake. Object reference not set to an instance of object.

    
asked by anonymous 31.08.2016 / 18:10

1 answer

2
  

But would not it be better to use the table itself already created by identity AspNetUsers?

This form already uses this table. What happens is that the Models created by deriving IdentityUser will all be records of the AspNetUsers table.

  

I'm a little confused, because then I'll put some "student", "teacher", "admin", "operator", etc. roles that will be the access level in the system administrative panel.

Depending on the composition of your Model , filtering by Role may not be necessary. Roles are interesting when there is no clear distinction between users. As in this case there is a well-modeled distinction, permissioning can be done by checking whether the user exists as that derivation. For example:

// Se usuário é aluno
var userId = User.Identity.GetUserId();
var aluno = db.Alunos.FirstOrDefault(a => a.Id == userId); // retorna um Aluno
var professor = db.Professores.FirstOrDefault(p => p.Id == userId); // retorna null
    
31.08.2016 / 18:29