1

Is it possible to have different profiles for different roles? or do I have to:

  1. Create a profile with all the fields that are shared i.e. First Name, Last Name.
  2. Create two separate tables that each include their own unique properties i.e. Table 1: DOB Table 2: Address and link to the profile?
Cool Breeze
  • 1,289
  • 11
  • 34

2 Answers2

1

You can use your identity user like this and then add a new Entity Teacher and Student:

public class User: IdentityUser
{
    [Required]
    [StringLength(100)]
    public string FirstName { get; set; }

    [Required]
    [StringLength(100)]
    public string LastName { get; set; }

    public DateTime JoinedOn { get; set; }
    public virtual Student Student { get; set; }

    public virtual Teacher Teacher { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
        UserManager<User, Guid> manager)
    {
        // Note the authenticationType must match the one defined in
        // CookieAuthenticationOptions.AuthenticationType 
        var userIdentity = await manager.CreateIdentityAsync(
            this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here 
        return userIdentity;
    } 
}
jubair
  • 597
  • 1
  • 6
  • 23
0

You may Create different profile for different role. Suppose you have a User table and you have some roles like student, teacher, administrator. You can create a one to one relation between user and student, user and teacher, user and administrator. Attributes specific for Student keep those in Student table.

Edit1:

So you are right you can create the user with common attributes and other tables with attributes specific to them.

jubair
  • 597
  • 1
  • 6
  • 23
  • Would I be able to access the student, teacher, administrator data via the Identity API or would I have to map this to my model myself? – Cool Breeze Apr 08 '15 at 11:19