コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Nome,Ano,Descricao,Autor")] AlbumViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         Album album = Mapper.Map <AlbumViewModel, Album>(viewModel);
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(viewModel));
 }
コード例 #2
0
        public void UpsertShouldChangeTheFildValues()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldChangeTheFildValues))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var original    = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "Original",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);


                var film = new Lab3.ViewModels.FilmPostModel
                {
                    Title = "upsert"
                };

                context.Entry(original).State = EntityState.Detached;

                var result = filmService.Upsert(1, film);

                Assert.IsNotNull(original);
                Assert.AreEqual("upsert", result.Title);
            }
        }