/// <summary> /// Update an existing video game in DB /// </summary> /// <param name="id"></param> /// <param name="videogame"></param> /// <returns> /// Returns NoContentResult on success /// Returns Bad Request if id to be updated does not match the id of videogame object /// /// </returns> public async Task <IActionResult> PutVideogame(int id, Videogame videogame) { if (id != videogame.VideogameId) { return(new BadRequestResult()); } _context.Entry(videogame).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VideogameExists(id)) { return(new NotFoundResult()); } else { throw; } } catch (Exception) { throw; } return(new NoContentResult()); }
public void Example() { #region Usage Videogame starcraft = new Videogame { Name = "Starcraft", ReleaseDate = new DateTime(1998, 1, 1) }; string json = JsonConvert.SerializeObject(starcraft, Formatting.Indented); Console.WriteLine(json); // { // "name": "Starcraft", // "release_date": "1998-01-01T00:00:00" // } #endregion StringAssert.AreEqual( @"{ ""name"": ""Starcraft"", ""release_date"": ""1998-01-01T00:00:00"" }", json ); }
static void Main(string[] args) { Livro l1 = new Livro("Harry Potter", 40.0, 50, "J K Rowling", "fantasia", 300); Livro l2 = new Livro("Senhor dos Anéis", 60.0, 30, "J R R Tolkien", "fantasia", 500); Livro l3 = new Livro("Java POO", 20.0, 50, "GFT", "educativo", 500); Videogame ps4 = new Videogame("PS4", 1000, 100, "Sony", "Slim", false); Videogame ps4Usado = new Videogame("PS4", 1000, 7, "Sony", "Slim", true); Videogame xbox = new Videogame("XBOX", 1500, 500, "Microsoft", "One", false); List <Livro> livros = new List <Livro>(); livros.Add(l1); livros.Add(l2); livros.Add(l3); List <Videogame> games = new List <Videogame>(); games.Add(ps4); games.Add(ps4Usado); games.Add(xbox); Loja americanas = new Loja("Americanas", "12345678", livros, games); l2.CalcularImposto(); l3.CalcularImposto(); ps4Usado.CalcularImposto(); ps4.CalcularImposto(); americanas.ListarLivros(); americanas.ListarVideoGames(); americanas.CalcularPatrimonio(); }
public static void WriteGameToConsole(Videogame game) { Console.WriteLine(game.Name); Console.WriteLine(game.System); Console.WriteLine(game.Genre); Console.WriteLine(game.Publisher); Console.WriteLine(game.Year); Console.WriteLine(); }
public ActionResult Edit(Videogame vg) { var Name = vg.Name; var Price = vg.Price; var Description = vg.Description; var MRequirements = vg.MinimumRequirements; return(RedirectToAction("Index")); }
public ActionResult Create(Videogame videogame) { if (ModelState.IsValid) { db.Videogames.Add(videogame); db.SaveChanges(); return(RedirectToAction("Index", "Produto")); } return(View(videogame)); }
public IActionResult Add(Videogame game) { if (ModelState.IsValid) { context.Create(game); return(Redirect("/")); } ViewBag.Games = context.Games; return(View("Index")); }
public IActionResult Update(int GameId, Videogame editedGame) { if (ModelState.IsValid) { context.Update(GameId, editedGame); return(Redirect("/")); } editedGame.VideogameId = GameId; Console.WriteLine(editedGame.VideogameId); return(View("Edit", editedGame)); }
public static void Update(string oldName, Videogame newGame) { foreach (Videogame game in videogames) { if (game.Name == oldName) { Delete(game.Name); } break; } Create(newGame); }
public static bool ValidateCreate(Videogame game) { Handler.ReadGames(); bool valid = ValidateGame(game); if (valid == true) { Handler.Create(game); } Handler.WriteGames(); return(valid); }
public void Add_EmptyDatabase_OneElementAdded() { //Arrange var database = VideogameMockDatabase.Instance; var videogame = new Videogame("a", "b", 1); //Act database.Add(videogame); //Assert Assert.AreEqual(database.VideogameList.Count, 1); }
public async Task <IActionResult> Create(Videogame videogame) { if (ModelState.IsValid) { _db.Add(videogame); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(videogame)); }
public void SetUp() { videogames = VideogameFactory.CreateFullVideoGameLibrary(); v1 = new Videogame("Grand Theft Auto V", Platform.PS3, 2013, "Action", "Take-Two Interactive", 6.25, 8.02, 0.85, 3.93); v2 = new Videogame("FIFA Soccer 14", Platform.PS3, 2013, "Sports", "Electronic Arts", 0.70, 4.04, 0.07, 2.00); v3 = new Videogame("SpongeBob's Truth or Square", Platform.Xbox360, 2009, "Action", "THQ", 0.03, 0.04, 0.00, 0.00); v4 = new Videogame("Guilty Gear XX Accent Core", Platform.Wii, 2007, "Fighting", "505 Games", 0.03, 0.00, 0.00, 0.00); v5 = new Videogame("Thomas & Friends: Hero of the Rails", Platform.Wii, 2010, "Misc", "Unknown", 0.00, 0.01, 0.00, 0.00); aux = new Videogame[10]; }
public static bool ValidateGame(Videogame game) { bool valid = true; if (string.IsNullOrEmpty(game.Name) || game.Name.Contains('~') || string.IsNullOrEmpty(game.Genre) || game.Genre.Contains('~') || string.IsNullOrEmpty(game.Publisher) || game.Publisher.Contains('~') || string.IsNullOrEmpty(game.System) || game.System.Contains('~')) { valid = false; } return(valid); }
public static void TestJsonProperty() { Videogame starcraft = new Videogame { Name = "Starcraft", ReleaseDate = new DateTime(1998, 1, 1) }; string json = JsonConvert.SerializeObject(starcraft); Assert.AreEqual("{\"name\":\"Starcraft\",\"release_date\":\"1998-01-01T00:00:00\"}", json, "Specified property names reflected in serialized string."); }
/// <summary> /// Add a new video game to DB /// </summary> /// <param name="videogame"></param> /// <returns> /// Newly created videogame /// </returns> public async Task <ActionResult <Videogame> > PostVideogame(Videogame videogame) { try { _context.Videogames.Add(videogame); await _context.SaveChangesAsync(); return(videogame); } catch { throw; } }
public static Videogame RetrieveOne(string name) { Videogame videogame = new Videogame(); foreach (Videogame game in videogames) { if (game.Name == name) { videogame = game; break; } } return(videogame); }
public static bool ValidateUpdate(string oldName, Videogame game) { Handler.ReadGames(); bool validName = NameValidator(oldName); bool validGame = ValidateGame(game); bool overallValidity = false; if (validName == true && validGame == true) { overallValidity = true; Handler.Update(oldName, game); } Handler.WriteGames(); return(overallValidity); }
public static Videogame ValidateRetrieveOne(string input) { Handler.ReadGames(); Videogame game = new Videogame(); bool valid = NameValidator(input); if (valid == true) { game = Handler.RetrieveOne(input); } Handler.WriteGames(); //Will be coupled with ValidateGame() to complete validation. ///ValidateGame(ValidateRetrieveOne(input)) return(game); }
public void Constructor_WhenCalled_ReturnsVideogameWithCorrectParameters() { //Arrange Videogame other = new Videogame("title", "type", "description", "achievements"); //Act videogame = new Videogame("title", "type", "description", "achievements"); //Assert Assert.AreEqual(other.Title, videogame.Title); Assert.AreEqual(other.Type, videogame.Type); Assert.AreEqual(other.Description, videogame.Description); Assert.AreEqual(other.Achievements, videogame.Achievements); }
public ActionResult EditVG(Videogame videogame) { if (ModelState.IsValid) { var videogameUpdate = db.Videogames.First(c => c.ProdutoID == videogame.ProdutoID); videogameUpdate.Nome = videogame.Nome; videogameUpdate.Descricao = videogame.Descricao; videogameUpdate.Valor = videogame.Valor; videogameUpdate.QtdEstoque = videogame.QtdEstoque; videogameUpdate.Marca = videogame.Marca; videogameUpdate.Modelo = videogame.Modelo; db.SaveChanges(); return(RedirectToAction("Index", "Produto")); } return(View(videogame)); }
public async Task <ActionResult <Videogame> > PostVideogame(Videogame videogame) { try { var result = await videogameService.PostVideogame(videogame); //return result; return(CreatedAtAction("GetVideogame", new { id = result.Value.VideogameId }, videogame)); } catch (Exception ex) { Serilog.Log.Error(ex, "api/Videogames-> Error in PostVideogame controller"); return(StatusCode(500)); } }
public async Task <IActionResult> Edit(int?id, Videogame videogame) { if (id != videogame.Id) { return(NotFound()); } if (ModelState.IsValid) { _db.Update(videogame); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(videogame)); }
public void Example() { #region Usage string json = @"{ 'Name': 'Starcraft III', 'ReleaseDate': null }"; Videogame starcraft = JsonConvert.DeserializeObject <Videogame>(json); Console.WriteLine(starcraft.Name); // Starcraft III Console.WriteLine(starcraft.ReleaseDate); // null #endregion }
static void Main(string[] args) { Livro l1 = new Livro("Harry Potter", 40, 50, "J. K. Rowling", "fantasia", 300); Livro l2 = new Livro("Senhor dos Anéis", 60, 30, "J. R. R. Tolkien", "fantasia", 500); Livro l3 = new Livro("Java POO", 20, 50, "GFT", "education", 500); Videogame g1 = new Videogame("PS4", 1800, 100, "Sony", "Slim", false); Videogame g2 = new Videogame("PS4", 1000, 7, "Sony", "Slim", true); Videogame g3 = new Videogame("XBOX", 1500, 500, "Microsoft", "One", false); var livros = new List <Livro>(); livros.Add(l1); livros.Add(l2); livros.Add(l3); var games = new List <Videogame>(); games.Add(g1); games.Add(g2); games.Add(g3); Loja americanas = new Loja("Americanas", "12345678", livros, games); foreach (Livro livro in livros) { if (livro.calculaImposto() == 0) { Console.WriteLine("O livro " + livro.nome + " não contem imposto."); } else { Console.WriteLine("O livro " + livro.nome + " tem R$ " + livro.calculaImposto() + " de imposto."); } } foreach (Videogame game in games) { Console.WriteLine("O " + game.nome + " tem R$ " + game.calculaImposto() + " de imposto."); } Console.WriteLine("_____________________________________________"); americanas.listaLivros(); Console.WriteLine("_____________________________________________"); americanas.listaVideoGames(); Console.WriteLine("_____________________________________________"); Console.WriteLine("O patrimonio da loja: A " + americanas.nome + " é de R$ " + americanas.calculaPatrimonio()); }
public void Example() { #region Usage Videogame starcraft = new Videogame { Name = "Starcraft", ReleaseDate = new DateTime(1998, 1, 1) }; string json = JsonConvert.SerializeObject(starcraft, Formatting.Indented); Console.WriteLine(json); // { // "name": "Starcraft", // "release_date": "1998-01-01T00:00:00" // } #endregion }
public async Task <IActionResult> PutVideogame(int id, Videogame videogame) { try { var result = await videogameService.PutVideogame(id, videogame); return(result); } catch (DbUpdateConcurrencyException dbex) { Serilog.Log.Error(dbex, "api/Videogames-> Concurrency exception in PutVideogame controller"); return(StatusCode(409)); } catch (Exception ex) { Serilog.Log.Error(ex, "api/Videogames-> Error in PutVideogame controller"); return(StatusCode(500)); } }
static void Main(string[] args) { var gamingPC = new Computer("RTX 2080", "M.2", "128GB"); var lamePC = new Computer("Intel Integrated Graphics", "HDD", "125MB"); var megamanX = new Videogame("Megaman X", "Retro"); var rocketLeague = new Videogame("Rocket League", "Sports"); var guitar = new Instrument("Guitar", true, "flame red"); var bowser = new Pet("Bowser", "Siberian Husky", 1); megamanX.Install(); rocketLeague.Install(); gamingPC.PlayGame(megamanX); lamePC.PlayGame(rocketLeague); guitar.Play(); bowser.Fetch(); }
public void TestInitialize() { videogame = new Videogame(); }
public ActionResult Details(Videogame videogame) { return(View(videogame)); }
public ActionResult Edit(Videogame videogame) { return(View(videogame)); }