public Task <IActionResult> FetchAllStages(MatchRequest request) { //Recupero la lista dal layer var entities = BasicLayer.FetchAllStages(request.MatchId); //seleziono gli id dei posti var matchIds = entities.Select(x => x.MatchId).ToList(); //recupero gli utenti var matches = this.BasicLayer.FetchMatchesByIds(matchIds); var associationIds = matches.Select(x => x.AssociationId).ToList(); var associations = BasicLayer.FetchAssociationsByIds(associationIds); //Ritorno i contratti return(Reply(entities.As(x => { var match = matches.FirstOrDefault(p => p.Id == x.MatchId); return ContractUtils.GenerateContract(x, match, associations.FirstOrDefault(p => p.Id == match.AssociationId)); }))); }