I would assume i use some LINQ query for this but i can't get my head around it since i have to check multiple lists with different attributes. When i create a project i can choose the participants, but i want to be able to later add some more, but only show the ones that are not yet added. The project participants are saved in a table which has 2 columns: UserId and ProjectId .. But the users are shown in the multiple select form as an IEnumerable. This is what i tried so far:
public IEnumerable<SelectListItem> result { get; set; }
= new List<SelectListItem>();
public IEnumerable<SelectListItem> Items { get; set; }
= new List<SelectListItem>();
public void OnGet(int id)
{
ProjectList = _context.Projects.ToList();
TicketList = _context.Tickets.ToList();
UserList = _context.Users.ToList();
ProjectParticipantsList= _context.ProjectParticipants.ToList();
ID = id;
Items = (from usr in this._context.Users
select new SelectListItem
{
Text = usr.Email.ToString(),
Value = usr.Id.ToString()
}).ToList();
result = Items.Where(p => ProjectParticipantsList.All(p2 => (p2.UserId != p.Value) && (ProjectList.ElementAt(id).Id != p2.ProjectId)));
}
I don't know how to check both for the id of the project and the id of the users