public static bool ProcessMatchStats(MatchStats stats, string conStr) { using (SqlConnection con = new SqlConnection(conStr)) { con.Open(); if (stats != null) { DataTable toInsert = GetDataTable("dbo.tt_MatchStats", conStr); DataRow newRow = toInsert.NewRow(); foreach (DataColumn col in toInsert.Columns) { if (typeof(MatchStats).GetProperty(col.ColumnName).GetValue(stats) != null) { newRow[col] = typeof(MatchStats).GetProperty(col.ColumnName).GetValue(stats); } } toInsert.Rows.Add(newRow); SqlCommand cmd = new SqlCommand("usp_ProcessMatchStats", con) { CommandType = CommandType.StoredProcedure }; SqlParameter ttParam = cmd.Parameters.AddWithValue("@MatchStatsTT", toInsert); ttParam.SqlDbType = SqlDbType.Structured; cmd.ExecuteNonQuery(); return(true); } return(false); } }
public static List <MatchStats> GetMatchStats(dynamic PlayerStats, Dictionary <long, uint> CarIds, Dictionary <long, List <float> > CameraSettings, MatchData data) { List <MatchStats> StatList = new List <MatchStats>(); for (int i = 0; i < PlayerStats.Count; i++) { long PlatformId = PlayerStats[i]["OnlineID"].Value; int Team = PlayerStats[i]["Team"].Value; int Score = PlayerStats[i]["Score"].Value; int Goals = PlayerStats[i]["Goals"].Value; int Assists = PlayerStats[i]["Assists"].Value; int Saves = PlayerStats[i]["Saves"].Value; int Shots = PlayerStats[i]["Shots"].Value; bool Verdict = false; if (data.Team0Score > data.Team1Score && Team == 0 || data.Team0Score < data.Team1Score && Team == 1) { Verdict = true; } uint CarId = CarIds[PlatformId]; MatchStats temp; if (CameraSettings.ContainsKey(PlatformId)) { int FieldOfView = (int)CameraSettings[PlatformId][0]; int Height = (int)CameraSettings[PlatformId][1]; int Pitch = (int)CameraSettings[PlatformId][2]; int Distance = (int)CameraSettings[PlatformId][3]; decimal Stiffness = Math.Round((decimal)CameraSettings[PlatformId][4], 2); decimal SwivelSpeed = Math.Round((decimal)CameraSettings[PlatformId][5], 2); decimal TransitionSpeed = Math.Round((decimal)CameraSettings[PlatformId][6], 2); temp = new MatchStats(PlatformId, Team, Score, Goals, Assists, Saves, Shots, CarId, Verdict, data.MatchId, FieldOfView, Height, Pitch, Distance, Stiffness, SwivelSpeed, TransitionSpeed); } else { temp = new MatchStats(PlatformId, Team, Score, Goals, Assists, Saves, Shots, CarId, Verdict, data.MatchId); } StatList.Add(temp); } return(StatList); }