/// <summary> /// Gets the matches by event. /// </summary> /// <param name="eventt">The eventt.</param> /// <returns>List of matches</returns> public List <Match> GetMatchesByEvent(Event eventt) { List <Match> matches = new List <Match>(); Match match = null; DBTeam dBTeam = new DBTeam(); SqlDataReader reader; TransactionOptions to = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, to)) { using (SqlConnection connection = DBConnection.GetSqlConnection()) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "SELECT Id, Format, WinnerId, EventId FROM Match WHERE EventId = @EventId"; command.Parameters.AddWithValue("EventId", eventt.Id); reader = command.ExecuteReader(); while (reader.Read()) { match = new Match { Id = reader.GetInt32(reader.GetOrdinal("Id")), Format = reader.GetString(reader.GetOrdinal("Format")), EventId = reader.GetInt32(reader.GetOrdinal("EventId")) }; matches.Add(match); } reader.Close(); command.Parameters.Clear(); foreach (Match m in matches) { if (m != null) { GetMapsByMatch(m); m.Teams = dBTeam.GetTeamsByMatch(m); m.Winner = dBTeam.GetWinnerTeamByMatch(m); if (m.Teams.Count != 0) { m.GenerateName(m.Teams[0], m.Teams[1]); } } } } connection.Close(); } scope.Complete(); } return(matches); }
/// <summary> /// Gets the match by unique identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>The found match</returns> public Match GetMatch(int id) { DBTeam dBTeam = new DBTeam(); DBEvent dBEvent = new DBEvent(); Match match = null; int eventId = 0; List <Map> mapList = new List <Map>(); TransactionOptions to = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, to)) { using (SqlConnection connection = DBConnection.GetSqlConnection()) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "SELECT Id, Format, WinnerId, EventId FROM Match WHERE Id=@id"; command.Parameters.AddWithValue("Id", id); int winnerId = 0; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { match = new Match { Id = reader.GetInt32(reader.GetOrdinal("Id")), Format = reader.GetString(reader.GetOrdinal("Format")), EventId = reader.GetInt32(reader.GetOrdinal("EventId")) }; winnerId = reader.GetInt32(reader.GetOrdinal("WinnerId")); eventId = reader.GetInt32(reader.GetOrdinal("EventId")); } command.Parameters.Clear(); reader.Close(); if (match != null) { GetMapsByMatch(match); match.Teams = dBTeam.GetTeamsByMatch(match); match.Winner = dBTeam.GetTeam(winnerId); match.GenerateName(match.Teams[0], match.Teams[1]); } } connection.Close(); } scope.Complete(); } return(match); }