Ejemplo n.º 1
0
        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 :)");
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var genre = new Genre()
            {
                Id   = id,
                Name = collection["Name"]
            };
            var newGenre = genreService.Edit(genre);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 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));
     }
 }