public ChampionshipTeam UpdateChampionship(int id, UpdateChampionshipRequest request) { List <TeamScoreDTO> teams = new List <TeamScoreDTO>(request.teamScores); foreach (TeamScoreDTO t in teams) { var a = _context.Team.FirstOrDefault(x => x.IdTeam == t.idTeam); if (a == null) { return(null); } else { var updated = new ChampionshipTeam { IdTeam = t.idTeam, IdChampionship = id, Score = t.Score }; return(updated); } } return(null); }
public ChampionshipTeam getChampionshipTeams(int idChampionship) { ChampionshipTeam teams = new ChampionshipTeam(); string message = ""; using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s17470;Integrated Security=True")) using (var com = new SqlCommand()) { com.Connection = con; com.CommandText = "SELECT * FROM Championship_Team WHERE IdChampionship=@id"; com.Parameters.AddWithValue("id", idChampionship); var command = com.CommandText; con.Open(); var dr = com.ExecuteReader(); if (!dr.Read()) //jesli zapytanie NIC nie zwrocilo.. { throw new Exception("Wrong request."); } while (dr.Read()) { teams.IdChampionship = dr["IdChampionship"].ToString(); teams.IdTeam = dr["IdTeam"].ToString(); teams.Score = dr["Score"].ToString(); message = string.Concat(message, '\n', teams.IdChampionship, ", ", teams.IdTeam, ", ", teams.Score); } dr.Close(); } return(teams); }