public MovieModel(Domain.Movie movie) { Id = movie.Id; Name = movie.Name; Duration = movie.Duration; Synopsis = movie.Synopsis; Classification = movie.Classification; CategoryId = movie.Category.Id; CategoryName = movie.Category.Description; }
static void Main() { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseInMemoryDatabase(); // extension method from package entityframework.inmemory using (var context = new VideoStoreContext(optionsBuilder.Options)) { PrintEntitiesCount(context); var movie = new Movie { Name = "I am Legend" }; var actor = new Actor { FirstName = "Will", LastName = "Smith" }; movie.Actors.Add(actor); actor.Movies.Add(movie); context.AddRange(movie, actor); context.SaveChanges(); PrintEntitiesCount(context); } Console.ReadLine(); }
public ActionResult SaveOrUpdate(Movie movie, HttpPostedFileBase posterFile) { if (!string.IsNullOrEmpty(movie.PosterFileName)) { movie.PosterFileName = Path.GetFileName(movie.PosterFileName); } if (posterFile != null && posterFile.ContentLength > 0) { var fileName = Path.GetFileName(posterFile.FileName); var directory = Server.MapPath("~/Content/images/movies"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // Saves the original image if (fileName != null) { var originalFilePath = Path.Combine(directory, fileName); posterFile.SaveAs(originalFilePath); ThumbnailHandler.CreateAllThumbs(originalFilePath); } } using (var uow = new UnitOfWork(true)) { if (movie.Id != 0) { var oldMovie = uow.Movies.Find(movie.Id); oldMovie.Title = movie.Title; oldMovie.Genre = movie.Genre; oldMovie.Director = movie.Director; oldMovie.ReleaseDate = movie.ReleaseDate; oldMovie.PosterFileName = movie.PosterFileName; oldMovie.Summary = movie.Summary; oldMovie.WikipediaLink = movie.WikipediaLink; uow.Movies.SaveOrUpdate(oldMovie); } else { uow.Movies.SaveOrUpdate(movie); } uow.Commit(); } return RedirectToAction("View", new { id = movie.Id }); }