private void btnUpdate_Click(object sender, EventArgs e) { try { string id = txtId.Text; string nome = txtnome.Text; string marca = txtMarca.Text; VideoGames videoGames = new VideoGames(); videoGames.Id = Convert.ToInt32(id); videoGames.nome = nome; videoGames.marca = marca; videoGames.Update(); MessageBox.Show("Operação Realizada com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro ao tentar alterar. " + ex.Message, "Falha na operação", MessageBoxButtons.OK, MessageBoxIcon.Warning); } btnUpdate.Hide(); btnCancelar.Hide(); btnCadastro.Enabled = true; btnVisualizar.Enabled = true; btnAtualizar.Enabled = true; btnDeletar.Enabled = true; txtnome.Text = " "; txtMarca.Text = " "; }
public List <VideoGames> GetRandomGame() { DataSet myDS = new DataSet(); StoredProcedures stoPros = new StoredProcedures(); myDS = stoPros.getRandGame(); DBConnect objDB = new DBConnect(); VideoGames videogames = new VideoGames(); List <VideoGames> dpts = new List <VideoGames>(); foreach (DataRow dr in myDS.Tables[0].Rows) { videogames = new VideoGames(); videogames.GameID = int.Parse(dr["Video_Game_ID"].ToString()); videogames.GameName = dr["Video_Game_Name"].ToString(); videogames.GameYear = int.Parse(dr["Video_Game_Year"].ToString()); videogames.GameDescription = dr["Video_Game_Description"].ToString(); videogames.GameCreator = dr["Video_Game_Creator"].ToString(); videogames.GameAgeRating = dr["Video_Game_Age_Rating"].ToString(); videogames.GameGenre = dr["Video_Game_Genre"].ToString(); videogames.GameImage = dr["Video_Game_Image"].ToString(); dpts.Add(videogames); } return(dpts); }
public async Task <IActionResult> PutVideoGames([FromRoute] int id, [FromBody] VideoGames videoGames) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != videoGames.Id) { return(BadRequest()); } _context.Entry(videoGames).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VideoGamesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <VideoGames> > PostVideoGames(VideoGames videoGames) { _context.VideoGames.Add(videoGames); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVideoGames", new { id = videoGames.VideoGameId }, videoGames)); }
private void btnVisualizar_Click(object sender, EventArgs e) { VideoGames videoGames = new VideoGames(); dgvRegistro.DataSource = videoGames.Visualizar(); dgvRegistro.Show(); btnVoltar.Show(); }
private void btnOk_Click(object sender, EventArgs e) { dgvRegistro.Hide(); btnOk.Hide(); btnVoltar.Hide(); btnDelete.Hide(); btnUpdate.Show(); txtId.Hide(); lblInsiraId.Hide(); btnUpdate.Show(); btnCancelar.Show(); btnCadastro.Enabled = false; btnVisualizar.Enabled = false; btnAtualizar.Enabled = false; btnDeletar.Enabled = false; VideoGames videoGames = new VideoGames(); NpgsqlConnection conexao = null; try { conexao = ConectaDB.getConexao(); string sql = "SELECT nome,marca FROM registros WHERE id=@id "; NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@id", txtId.Text); NpgsqlDataReader leitor = cmd.ExecuteReader(); while (leitor.Read()) { txtnome.Text = leitor["nome"].ToString(); txtMarca.Text = leitor["marca"].ToString(); } txtnome.Focus(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (conexao != null) { conexao.Close(); } } }
public void ListarVideoGames(Loja loja) { Console.WriteLine("\nAs Lojas Americanas possui estes livros em estoque: \n"); foreach (var VideoGames in ListaVideoGame) { Patrimonio = Patrimonio + VideoGames.Preco; Console.WriteLine($"Nome: {VideoGames.Nome} | Preço: {VideoGames.CalcularImposto()} | Quantidade: {VideoGames.Quantidade} em estoque"); } }
public async Task <IActionResult> PostVideoGames([FromBody] VideoGames videoGames) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.VideoGames.Add(videoGames); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVideoGames", new { id = videoGames.Id }, videoGames)); }
private void btnCadastro_Click(object sender, EventArgs e) { try { VideoGames videoGames = new VideoGames(); if (txtnome.Text.Trim() == string.Empty || txtMarca.Text.Trim() == string.Empty) { MessageBox.Show("Existem campos vazios", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtnome.BackColor = Color.Red; txtMarca.BackColor = Color.Red; } else { string Nome = txtnome.Text; string Marca = txtMarca.Text; txtnome.Text = " "; txtMarca.Text = " "; videoGames.nome = Nome; videoGames.marca = Marca; videoGames.Cadastrar(); MessageBox.Show("Cadastrado com sucesso! "); txtnome.BackColor = Color.White; txtMarca.BackColor = Color.White; } } catch (Exception ex) { MessageBox.Show("Erro!", "Erro ao Cadastrar!", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtnome.Text = " "; txtMarca.Text = " "; txtnome.Focus(); } }
static void Main(string[] args) { var goodBook = new Books(); var badBook = new Books(); var bestPet = new Pets(); var worstPet = new Pets(); var badFriend = new Friends(); var favoriteFriend = new Friends(); var bestGame = new VideoGames(); var worstGame = new VideoGames(); goodBook.Shelf(); badBook.Open(); Console.ReadLine(); }
public bool CreateGame(GameCreate model) { var entity = new VideoGames() { OwnerId = _userId, GameTitle = model.GameTitle, Console = model.Console, GenreType = model.GenreType, Price = model.Price, ReleaseYear = model.ReleaseYear, CreatedUtc = DateTimeOffset.Now, Quantity = model.Quantity }; using (var ctx = new ApplicationDbContext()) { ctx.VideoGame.Add(entity); return(ctx.SaveChanges() == 1); } }
private void btnDelete_Click(object sender, EventArgs e) { { try { VideoGames videoGames = new VideoGames(); videoGames.Id = Convert.ToInt16(txtId.Text); videoGames.Deletar(); if (txtId.Text.Trim() == string.Empty) { MessageBox.Show("Preencha o ID !!!", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Operação realizada com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dgvRegistro.Hide(); btnVoltar.Hide(); btnDelete.Hide(); txtId.Hide(); lblInsiraId.Hide(); txtnome.Text = " "; txtMarca.Text = " "; txtId.Text = " "; txtId.BackColor = Color.White; } } catch (Exception ex) { MessageBox.Show("Preencha o ID !!!", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Error); txtId.BackColor = Color.Red; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Session["NewMovieInfo"] != null || Session["AddNewMovie"] != null) { if (ddlAddMovieAgeRange.SelectedValue == "noneSelected") { lblDisplay.Text = "Select an Age Rating"; } else { if (ddlAddMovieGenre.SelectedValue == "noneSelected") { lblDisplay.Text = "Select a Genre"; } else { if (ddlAddMovieYear.SelectedValue == "noneSelected") { lblDisplay.Text = "Select a Year"; } else { Movies movie = new Movies(); movie.memberID = Convert.ToInt32(Session["MemberID"].ToString()); if (Session["Edit_ID"] != null) { movie.movieID = Convert.ToInt32(Session["Edit_ID"].ToString()); } movie.movieImage = txtAddMovieImage.Text; movie.movieName = txtAddMovieName.Text; movie.movieYear = Convert.ToInt32(ddlAddMovieYear.Text); movie.movieDescription = txtAddMovieDescription.Text; movie.movieRuntime = Convert.ToInt32(txtAddMovieRuntime.Text); movie.movieAgeRating = ddlAddMovieAgeRange.Text; movie.movieGenre = ddlAddMovieGenre.Text; movie.movieBudget = float.Parse(txtAddMovieBudget.Text); movie.movieIncome = float.Parse(txtAddMovieIncome.Text); JavaScriptSerializer js = new JavaScriptSerializer(); String jsonMovie = js.Serialize(movie); try { if (Session["NewMovieInfo"] != null) { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/movies/UpdateMovie/"); request.Method = "PUT"; request.ContentLength = jsonMovie.Length; request.ContentType = "application/json"; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonMovie); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { lblDisplay.Text = "The movie was successfully edited."; Response.Write("<script>alert('Movie Updated successfully')</script>"); } else { lblDisplay.Text = "Make sure you are only editting your own added listing!"; } } else { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/movies/AddMovie/"); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = jsonMovie.Length; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonMovie); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { lblDisplay.Text = "The movie was successfully saved to the database."; Response.Write("<script>alert('Movie inserted successfully')</script>"); } else { lblDisplay.Text = "A problem occurred while adding the movie to the database. The data wasn't recorded."; } } } catch (Exception ex) { lblDisplay.Text = "Error: " + ex.Message; } } } } Session["NewMovieInfo"] = null; } else if (Session["NewShowInfo"] != null || Session["AddNewShow"] != null) { if (ddlAddShowAgeRating.SelectedValue == "noneSelected") { lblDisplay2.Text = "Please Select an Age Rating"; } else { if (ddlAddShowGenre.SelectedValue == "noneSelected") { lblDisplay2.Text = "Please Select a Genre"; } else { if (ddlAddShowYearsStart.SelectedValue == "noneSelected") { lblDisplay2.Text = "Please Select Run Years Value"; } else { if (ddlAddShowYearsEnd.SelectedValue == "noneSelected") { lblDisplay2.Text = "Please Select Run Years Value"; } else { TVShows show = new TVShows(); show.MemberID = Convert.ToInt32(Session["MemberID"].ToString()); if (Session["Edit_ID"] != null) { show.ShowID = Convert.ToInt32(Session["Edit_ID"].ToString()); } show.ShowImage = txtAddShowImage.Text; show.ShowName = txtAddShowName.Text; show.ShowYears = ddlAddShowYearsStart.Text + "-" + ddlAddShowYearsEnd.Text; show.ShowAgeRating = ddlAddShowAgeRating.Text; show.ShowRuntime = Convert.ToInt32(txtAddShowRuntime.Text); show.ShowGenre = ddlAddShowGenre.Text; show.ShowDescription = txtAddShowDescription.Text; JavaScriptSerializer js = new JavaScriptSerializer(); String jsonShow = js.Serialize(show); try { if (Session["NewShowInfo"] != null) { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/show/UpdateShow/"); request.Method = "PUT"; request.ContentLength = jsonShow.Length; request.ContentType = "application/json"; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonShow); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { Response.Write("<script>alert('Show updated successfully')</script>"); } // lblDisplay.Text = "The Show was successfully edited."; else { lblDisplay2.Text = "Make sure you are only editting your own added listing!"; } } else { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/show/AddShow/"); request.Method = "POST"; request.ContentLength = jsonShow.Length; request.ContentType = "application/json"; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonShow); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { Response.Write("<script>alert('Show inserted successfully')</script>"); } //lblDisplay.Text = "The show was successfully saved to the database."; else { lblDisplay2.Text = "A problem occurred while adding the show to the database. The data wasn't recorded."; } } } catch (Exception ex) { lblDisplay2.Text = "Error: " + ex.Message; } } } } } Session["NewShowInfo"] = null; } else if (Session["NewGameInfo"] != null || Session["AddNewGame"] != null) { if (ddlAddGameAgeRating.SelectedValue == "noneSelected") { lblDisplay3.Text = "Please Select Age Rating"; } else { if (ddlAddGameGenre.SelectedValue == "noneSelected") { lblDisplay3.Text = "Please Select Genre"; } else { if (ddlAddGameYear.SelectedValue == "noneSelected") { lblDisplay3.Text = "Please Select Release Year"; } else { VideoGames game = new VideoGames(); game.MemberID = Convert.ToInt32(Session["MemberID"].ToString()); if (Session["Edit_ID"] != null) { game.GameID = Convert.ToInt32(Session["Edit_ID"].ToString()); } game.GameImage = txtAddGameImage.Text; game.GameName = txtAddGameName.Text; game.GameYear = Convert.ToInt32(ddlAddGameYear.Text); game.GameGenre = ddlAddGameGenre.Text; game.GameDescription = txtAddGameDescription.Text; game.GameCreator = txtAddGameCreator.Text; game.GameAgeRating = ddlAddGameAgeRating.Text; JavaScriptSerializer js = new JavaScriptSerializer(); String jsonGame = js.Serialize(game); try { if (Session["NewGameInfo"] != null) { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/game/UpdateGame/"); request.Method = "PUT"; request.ContentLength = jsonGame.Length; request.ContentType = "application/json"; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonGame); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { Response.Write("<script>alert('Game updated successfully')</script>"); } //lblDisplay.Text = "The game was successfully edited."; else { lblDisplay3.Text = "Make sure you are only editting your own added listing!"; } } else { WebRequest request = WebRequest.Create("https://localhost:44301/WebAPI/game/AddGame/"); request.Method = "POST"; request.ContentLength = jsonGame.Length; request.ContentType = "application/json"; // Write the JSON data to the Web Request StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.Write(jsonGame); writer.Flush(); writer.Close(); // Read the data from the Web Response, which requires working with streams. WebResponse response = request.GetResponse(); Stream theDataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(theDataStream); String data = reader.ReadToEnd(); reader.Close(); response.Close(); if (data == "true") { Response.Write("<script>alert('Game added successfully')</script>"); } //lblDisplay.Text = "The game was successfully saved to the database."; else { lblDisplay3.Text = "A problem occurred while adding the game to the database. The data wasn't recorded."; } } } catch (Exception ex) { lblDisplay.Text = "Error: " + ex.Message; } } } } } Session["NewGameInfo"] = null; }