public static ESRB AddESRB(ESRB esrb) { //get connection using (SqlConnection conn = DB.GetConnection()) { //define a command using (SqlCommand cmd = new SqlCommand()) { //NOTE: this is done with SQL in the code... //You are expected to create a Stored Proc //to do the insert. Refer to update and delete //examples cmd.Connection = conn; cmd.CommandText = "InsertESRB"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ESRBRating", esrb.Rating); //run the command int newId = (int)cmd.ExecuteScalar(); //set the id with the new row id esrb.ESRBID = newId; //return the updated category object //that now contains the id of the new category return(esrb); } } }
public static ESRB GetESRB(int ESRBID) { using (SqlConnection conn = DB.GetConnection()) { //Create a comnmand using the connection using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "GetESRB"; cmd.Parameters.AddWithValue("@esrbid", ESRBID); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { // create an object ESRB e = new ESRB(); e.ESRBID = reader.GetInt32(0); e.Rating = reader.GetString(1); return(e); } else { return(null); } } } }
public static List <ESRB> GetESRBList() { //create empty list to hold objects List <ESRB> esrbs = new List <ESRB>(); //get a connection from DB class using (SqlConnection conn = DB.GetConnection()) { //Create a comnmand using the connection using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "SELECT * FROM ESRB"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //generate a new object // and fill it with data from reader ESRB esrb = new ESRB(); esrb.ESRBID = reader.GetInt32(0); esrb.Rating = reader.GetString(1); //add the filled category to my list esrbs.Add(esrb); } } } //return the list return(esrbs); }
public async Task <ActionResult <ESRB> > PostESRB(ESRB eSRB) { _context.ESRBs.Add(eSRB); await _context.SaveChangesAsync(); return(CreatedAtAction("GetESRB", new { id = eSRB.ESRBId }, eSRB)); }
public async Task <IActionResult> PutESRB(int id, ESRB eSRB) { if (id != eSRB.ESRBId) { return(BadRequest()); } _context.Entry(eSRB).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ESRBExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> GetESRB(int id) { ESRB eSRB = await db.Ratings.FindAsync(id); if (eSRB == null) { return(NotFound()); } return(Ok(eSRB)); }
public Game() { tags = new List <long>(); themes = new List <long>(); genres = new List <long>(); keywords = new List <long>(); developers = new List <long>(); publishers = new List <long>(); game_modes = new List <long>(); game_engines = new List <long>(); pegi = new PEGI(); esrb = new ESRB(); cover = new Cover(); websites = new List <Website>(); screenshots = new List <Image>(); release_dates = new List <ReleaseDate>(); alternative_names = new List <Alternative_name>(); }
public static int UpdateESRB(ESRB esrb) { //get the connection using (SqlConnection conn = DB.GetConnection()) { //define the command using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "UpdateESRB"; cmd.CommandType = System.Data.CommandType.StoredProcedure; //fill in all parameters that the stored proc expects cmd.Parameters.AddWithValue("@esrbid", esrb.ESRBID); cmd.Parameters.AddWithValue("@rating", esrb.Rating); //run the command int rowsAffected = cmd.ExecuteNonQuery(); return(rowsAffected); } } }
public GameDetails() { tags = new List <long>(); themes = new List <long>(); games = new List <Game>(); genres = new List <Genre>(); keywords = new List <Keyword>(); developers = new List <People>(); publishers = new List <People>(); game_modes = new List <Game_Mode>(); game_engines = new List <Game_Engine>(); pegi = new PEGI(); esrb = new ESRB(); cover = new Cover(); videos = new List <Igdb_Video>(); websites = new List <Website>(); screenshots = new List <Image>(); release_dates = new List <ReleaseDate>(); alternative_names = new List <Alternative_name>(); }