Extraction of different data from two object lists

Asked

Viewed 61 times

0

I am working on a WEB API and need to remove some values contained in one list and which are contained in another. To be better illustrated would be the equivalent of removing the data from a list where the user in question has already registered. Below follows the method Get of web api that is making the request and the way I am doing to try to make this extraction but the same is just returning me the values that the user has already registered first followed by all values of the table later, could give me a light please.

// GET: api/Jogos?ID_Jogador
public IEnumerable<Jogos> GetJogos(long ID_Jogador)
{
    //Desabilita a criação de proxy que gera erros na chamada
    //db.Configuration.ProxyCreationEnabled = false;

    var query =
       (
            from jO in db.Jogos
            from jJ in db.JogosJogador
            where jJ.ID_Jogador == ID_Jogador && jJ.ID_Jogo == jO.ID_Jogo
            select new
            {
                jO.ID_Jogo,
                jO.Nome_Jogo,
                jO.Nome_Icone_Jogo,
                jO.Plataforma,
                jO.Genero
            }
        );
    List<Jogos> jogosJogadorTem = new List<Jogos>();
    foreach (var item in query)
    {
        jogosJogadorTem.Add(new Jogos
        {
            ID_Jogo = item.ID_Jogo,
            Nome_Jogo = item.Nome_Jogo,
            Nome_Icone_Jogo = item.Nome_Icone_Jogo,
            Genero = item.Genero,
            Plataforma = item.Plataforma
        });
    }
    List<Jogos> todosJogos = db.Jogos.ToList();
    var diferenca1 = jogosJogadorTem.Except(todosJogos);
    var diferenca2 = todosJogos.Except(jogosJogadorTem);
    var juncao = diferenca2.Union(diferenca1).ToList();
    return juncao.ToList();
}
  • Can you explain it better? I couldn’t understand what you want to do by reading the description and the code.

  • You want to show all the games the user does not have?

  • Thank you very much for your attention but the comment below has already met my need.

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.