public Task <IActionResult> FetchAvailableGroupShooter(GroupRequest request) { //Recupero l'elemento dal business layer var entity = BasicLayer.GetGroup(request.GroupId); //modifica solo se admin o se utente richiedente è lo stesso che ha creato if (entity == null) { return(Task.FromResult <IActionResult>(NotFound())); } //Invocazione del service layer var shooters = BasicLayer.FetchAvailableShooters(entity); var shooterIds = shooters.Select(s => s.Id).ToList(); var shooterAssociation = BasicLayer.FetchShooterAssociationByShooterIds(shooterIds, entity.MatchId); var shooterTeams = BasicLayer.FetchTeamsFromShooterIds(shooterIds); var teamsIds = shooterTeams.Select(x => x.TeamId).ToList(); var teams = BasicLayer.FetchTeamsByIds(teamsIds); var result = shooters.As(x => ContractUtils.GenerateContract(x, shooterAssociation.Where(s => s.ShooterId == x.Id).ToList(), teams.Where(s => shooterTeams.Where(st => st.ShooterId == x.Id).Select(st => st.TeamId).Contains(s.Id)) .ToList())); //Return contract return(Reply(result)); }