public List <VideoGameModel> GetAllVideoGames() { List <VideoGameModel> videoGames = new List <VideoGameModel>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_AllGames, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { VideoGameModel v = new VideoGameModel(); v.ProductID = Convert.ToInt32(reader["product_id"]); v.Name = Convert.ToString(reader["product"]); v.Price = Convert.ToDouble(reader["price"]); v.Description = Convert.ToString(reader["description"]); v.CategoryID = Convert.ToInt32(reader["category_id"]); v.ImageName = Convert.ToString(reader["image"]); v.Trailer = Convert.ToString(reader["video"]); videoGames.Add(v); } } } catch (SqlException ex) { throw; } return(videoGames); }
public VideoGameModel GetGame(int id) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_SingleGame, conn); cmd.Parameters.AddWithValue("@id", id); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); VideoGameModel singleGame = new VideoGameModel(); singleGame.ProductID = Convert.ToInt32(reader["product_id"]); singleGame.Name = Convert.ToString(reader["product"]); singleGame.Price = Convert.ToInt32(reader["price"]); singleGame.Description = Convert.ToString(reader["description"]); singleGame.CategoryID = Convert.ToInt32(reader["category_id"]); singleGame.ImageName = Convert.ToString(reader["image"]); singleGame.Trailer = Convert.ToString(reader["video"]); return(singleGame); } } catch { throw; } }
public List <VideoGameModel> AllGames(string id) { List <VideoGameModel> All_Games = new List <VideoGameModel>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_All_Games, conn); cmd.Parameters.AddWithValue("@id", id); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { VideoGameModel games = new VideoGameModel(); games.Title = Convert.ToString(reader["title"]); games.Comments = Convert.ToString(reader["comments"]); games.Backlog = Convert.ToBoolean(reader["backlog"]); games.Playing = Convert.ToBoolean(reader["playing"]); games.Played = Convert.ToBoolean(reader["played"]); games.DateAdded = Convert.ToDateTime(reader["DateAdded"]); games.ImageUrl = Convert.ToString(reader["BoxArt"]); All_Games.Add(games); } } return(All_Games); } catch (SqlException ex) { throw; } }
public ActionResult Detail(int id) { VideoGameStoreDAL dal = new VideoGameStoreDAL(); VideoGameModel game = dal.GetGame(id); return(View("Detail", game)); }
[ValidateAntiForgeryToken] // Second level of security if JavaScript fails or is turned off public IActionResult AddGame(VideoGameModel videoGame) { if (ModelState.IsValid) { int recordsCreated = VideoGameProcessor.CreateVideoGame(videoGame.GameTitle, videoGame.ReleaseYear, videoGame.Platform, videoGame.Publisher, videoGame.CompleteCopy, videoGame.PhysicalCopy); return(RedirectToAction("Index")); // If data is valid it will post to the DB } return(View()); // If data is invalid it will return the View }
/// <summary> /// Maps a video game model back to a video game. /// </summary> /// <param name="videoGameModel">The video game model being mapped back to a video game.</param> /// <returns>A new video game model with all of the relevant properties of the video game model.</returns> public static VideoGame MapToVideoGame(VideoGameModel videoGameModel) { return(new VideoGame(videoGameModel.Title, videoGameModel.Cost.GetValueOrDefault(), videoGameModel.Genre, videoGameModel.Platform, videoGameModel.ReleaseYear.GetValueOrDefault(), videoGameModel.Developer, videoGameModel.Rating.GetValueOrDefault())); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } VideoGameModel = await _context.VideoGameModel.FirstOrDefaultAsync(m => m.Id == id); if (VideoGameModel == null) { return(NotFound()); } return(Page()); }
/// <summary> /// Maps a video game to a video game model. /// </summary> /// <param name="game">The video game being mapped to a video game model.</param> /// <returns>A new video game model with all of the relevant properties of the video game.</returns> public static VideoGameModel MapToVideoGameModel(VideoGame game) { // Create a new video game model. VideoGameModel gameModel = CreateNewModel <VideoGameModel>(); // Map all the common properties to the video game model. BaseInventoryModel baseModel = gameModel; MapCommonModel(game, ref baseModel); // Map the unique video game properties to the video game model. gameModel.Developer = game.Developer; gameModel.Rating = game.Rating; return(gameModel); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } VideoGameModel = await _context.VideoGameModel.FindAsync(id); if (VideoGameModel != null) { _context.VideoGameModel.Remove(VideoGameModel); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// Saves data from the Add Games form public static int CreateVideoGame(string GameTitle, string ReleaseYear, string Platform, string Publisher, bool CompleteCopy, bool PhsyicalCopy) { // Linking the MVC and Library Models VideoGameModel data = new VideoGameModel { GameTitle = GameTitle, ReleaseYear = ReleaseYear, Platform = Platform, Publisher = Publisher, CompleteCopy = CompleteCopy, PhysicalCopy = PhsyicalCopy }; // SQLite statement that adds the game info into the VideoGames table string sql = @"insert into VideoGames (GameTitle, ReleaseYear, Platform, Publisher, CompleteCopy, PhysicalCopy) values (@GameTitle, @ReleaseYear, @Platform, @Publisher, @CompleteCopy, @PhysicalCopy);"; return(SQLiteDataAccess.SaveData(sql, data)); }