0

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

  • It seems like you will need to use a join query. Also that you are wanting to be able to add a participant (user) to multiple projects provided they have not already been added for that project. This might give some ideas about constructing the join: https://stackoverflow.com/questions/3404975/left-outer-join-in-linq – Catherine May 05 '22 at 03:02

0 Answers0