public void EditShouldChangeGenreName() { var options = new DbContextOptionsBuilder <BookStoreDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; // var dbContext = new BookStoreDbContext(options); var genreServices = new GenreService(dbContext); var history = new Genre { Name = "History" }; dbContext.Genres.Add(history); var music = new Genre { Name = "Music" }; dbContext.Genres.Add(music); dbContext.SaveChanges(); genreServices.Edit(history.Id, "History and politic"); genreServices.Edit(music.Id, "Music hard rock :)"); Assert.True(history.Name == "History and politic"); Assert.True(music.Name == "Music hard rock :)"); }
public ActionResult Edit(int id, FormCollection collection) { var genre = new Genre() { Id = id, Name = collection["Name"] }; var newGenre = genreService.Edit(genre); return(RedirectToAction("Index")); }
public ActionResult <Genre> Edit([FromBody] Genre newGenre, int id) { try { newGenre.Id = id; return(Ok(_service.Edit(newGenre))); } catch (Exception e) { return(BadRequest(e.Message)); } }