Search code examples
c#asp.net-mvcasp.net-coreasp.net-identity

How do you link models/controllers to Identities? Asp.net core


I have two models/ and controllers ie User and tickets.

public class users
{
[key]
public string userName{get; set;}
public string ContactInfo{get; set;}
...etc
public List<Ticket> Tickets{get; set;}
}
public class Tickets
[key]
public int ticketNumber {get; set;}
public string issue {get; set;}
... etc
public string userName{get; set;}
public users user {get; set;}

I used individual user account authentication and can not figure out once an account is made linking it all together. The end goal is to have the normal users sign in, create, add info and see only their tickets. Then have master users who can see all users and tickets.


Solution

  • )

    You can do it by inheriting from IdentityUser and just adding properties from your user model to it and create relation with tickets. Then you can assign users to some roles, claims and show views, data depending on this. In your example, you would have just user and user in role "Master" or something and normal users would just see their tickets and master will have access to all tickets. I hope it is understandable for you.