public bool UpdateStats(StatsDAO StatsToUpdate) { bool success = false; try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { //command that will update a players stats using (SqlCommand _command = new SqlCommand("SP_UpsertStats", _connection)) { //Specify what command type will be used _command.CommandType = CommandType.StoredProcedure; //Command type being used _command.Parameters.AddWithValue("@Kills", StatsToUpdate.Kills); _command.Parameters.AddWithValue("@Deaths", StatsToUpdate.Deaths); _command.Parameters.AddWithValue("@Average", StatsToUpdate.Average); _command.Parameters.AddWithValue("@FKPlayerName", StatsToUpdate.FKPlayerName); //connection open _connection.Open(); //Execute command _command.ExecuteNonQuery(); //set bool to true success = true; } } } catch (Exception _Error) { //ErrorLogger _Logger.LogError(_Error); } return(success); }
public PO_Stats Map(StatsDAO _StatsToMap) { PO_Stats _StatsToReturn = new PO_Stats(); _StatsToReturn.Kills = _StatsToMap.Kills; _StatsToReturn.Deaths = _StatsToMap.Deaths; _StatsToReturn.Average = _StatsToMap.Average; _StatsToReturn.FKPlayerName = _StatsToMap.FKPlayerName; return(_StatsToReturn); }
//Stats Mapper public StatsDAO Map(PO_Stats _StatsToMap) { StatsDAO _StatsToReturn = new StatsDAO(); _StatsToReturn.Kills = _StatsToMap.Kills; _StatsToReturn.Deaths = _StatsToMap.Deaths; _StatsToReturn.Average = _StatsToMap.Average; _StatsToReturn.FKPlayerName = _StatsToMap.FKPlayerName; return(_StatsToReturn); }
public List <StatsDAO> GetAllStats() { List <StatsDAO> _StatsList = new List <StatsDAO>(); try { using (SqlConnection _connection = new SqlConnection(connectionstring)) { using (SqlCommand _command = new SqlCommand("SP_ViewAllStats", _connection)) { _connection.Open(); //Specify why kind of command used _command.CommandType = CommandType.StoredProcedure; using (SqlDataReader _reader = _command.ExecuteReader()) { if (_reader.HasRows) { while (_reader.Read()) { StatsDAO StatsToList = new StatsDAO(); StatsToList.FKPlayerName = _reader.GetString((_reader.GetOrdinal("FKPlayerName"))); StatsToList.Kills = _reader.GetInt32((_reader.GetOrdinal("Kills"))); StatsToList.Deaths = _reader.GetInt32((_reader.GetOrdinal("Deaths"))); StatsToList.Average = _reader.GetDecimal((_reader.GetOrdinal("Average"))); _StatsList.Add(StatsToList); } } else { Console.WriteLine("Sorry, no data found"); } } } } } catch (Exception _Error) { _Logger.LogError(_Error); } return(_StatsList); }
public StatsDAO viewSingleStat(string FKPlayerName) { StatsDAO StatToView = new StatsDAO(); try { // create connection to database using connection string variable using (SqlConnection _connection = new SqlConnection(connectionstring)) { // create command to view a team from the database using (SqlCommand _command = new SqlCommand("sp_ViewPlayerStats", _connection)) { // specify what type of command to use _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@FKPlayerName", FKPlayerName); // this is where the connection is opened _connection.Open(); // this is where all commands will be executed _command.ExecuteNonQuery(); // this accesses all the data given by the stored procedure using (SqlDataReader _reader = _command.ExecuteReader()) { while (_reader.Read()) { // create object to hold info from database StatToView.FKPlayerName = _reader.GetString(_reader.GetOrdinal("FKPlayerName")); StatToView.Kills = _reader.GetInt32((_reader.GetOrdinal("Kills"))); StatToView.Deaths = _reader.GetInt32((_reader.GetOrdinal("Deaths"))); StatToView.Average = _reader.GetDecimal((_reader.GetOrdinal("Average"))); } } } } } catch (Exception _error) { _Logger.LogError(_error); } return(StatToView); }
//Stats Methods public bool AddStats(StatsDAO StatToAdd) { bool success = false; try { //connection to the DB with a ConnectionString Variable using (SqlConnection _connection = new SqlConnection(connectionstring)) { //create the commnd to Add Stats to the DB using (SqlCommand _command = new SqlCommand("SP_UpsertStats", _connection)) { //Specify what command type will be used _command.CommandType = CommandType.StoredProcedure; //Below are the Values that will be sent to the command _command.Parameters.AddWithValue("@Kills", StatToAdd.Kills); _command.Parameters.AddWithValue("@Deaths", StatToAdd.Deaths); _command.Parameters.AddWithValue("@FKPlayerName", StatToAdd.FKPlayerName); //Connection Open _connection.Open(); //Execute the command _command.ExecuteNonQuery(); //set the bool to true success = true; } } } catch { //set the bool to false since it failed success = false; } return(success); }