I have 3 models:
Participant
Event
Enrollment
Each of them have their own tables in database. The target is to be able seeing Event
model data, Enrollment
model data and creating Participant
on one page.
Enrollment shows who of Participants
are assigned to the Event
.
Question: how to assign Participant
to the Event
so I could use Enrollment
?
P. S. If you would need additional information, tell me please. And sorry for inconvenience...
public class Event
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime Date { get; set; }
public string Location { get; set; }
public string Comment { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
//public ICollection<EventAssignment> EventAssignments { get; set; }
}
public class Participant
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string PersonalCode { get; set; }
public string PaymentType { get; set; }
public string Comment { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
}
public class Enrollment
{
public int ID { get; set; }
public int EventID { get; set; }
public int ParticipantID { get; set; }
public Participant Participant { get; set; }
public Event Event { get; set; }
}
//Creating Participant
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Participants.Add(Participant);
await _context.SaveChangesAsync();
return RedirectToPage("/Participants/Index");
}