Here is my mapping!
User to Admin 1 to 0..1 relationship??
Admin class has 2 properties: AdministratorID(Int) and AdministratorTitle(String)
One user can be one kind of admin status or no admin status
Users to Tickets 1 to Many relationship??
Users can open multiple tickets but a ticket can only be assigned to one User.
Administrator to Ticket 1 to Many relationship??
Admin (A user with admin status) has tickets assigned to him to fix. The ticket should have an AdminID to identify which admin is assigned to it .
The Ticket table should have: TicketID,AdminID(Admin assigned to fix it) and UserID(Person who created the ticket)
The User table should have : UserID, AdminID(0: Not an admin,1: Lvl 1 Admin, 2: Lvl 2 Admin) and TicketID(All the tickets that the User created)
The Administrator table should have: AdminID, UserID
My Question is do I need an Admin Class or not? Will I be able to show a table which has TicketID,UserID and AdminID(Shows the name of the User who is also an admin)
This is what I've done so far:
User.cs
public class User
{
public int UserID { get; set; }
public int? AdministratorID { get; set; }
[ForeignKey("AdministratorID")]
public virtual Administrator Administrator { get; set; }
public virtual ICollection<Ticket> Tickets { get; set; }
}
Administrator.cs
public class Administrator
{
public int AdministratorID { get; set; }
public string AdministratorTitle { get; set; }
// public virtual ICollection<Ticket> Tickets { get; set; }
public virtual ICollection<User> Users { get; set; }
}
}
Ticket.cs
public class Ticket
{
public int TicketID { get; set; }
public int UserID { get; set; }
[ForeignKey("UserID")]
public virtual User User { get; set; }
public int AdministratorID { get; set; }
[ForeignKey("AdministratorID")]
public virtual Administrator Administrator { get; set; }
}
Administratorneed a collection ofTickets if theUseralready has them? - Gert Arnold