コード例 #1
0
ファイル: Program.cs プロジェクト: csapp95/BCC_Project
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var service = scope.ServiceProvider;
                var context = service.GetRequiredService <MovieListingDbContext>();

                MovieDataGenerator.GenerateData(service);
            }

            host.Run();
        }
コード例 #2
0
        /// <summary>
        /// Updates the given movie entity if contained in the current context, else adds the new movie.
        /// </summary>
        /// <param name="movie"></param>
        /// <returns></returns>
        public bool SaveOrUpdate(Movie movie)
        {
            var hasMovie = _movieListingDbContext.GetMovie(movie.Id) != null;

            if (hasMovie)
            {
                _movieListingDbContext.Update(movie);
            }
            else
            {
                _movieListingDbContext.Add(movie);
            }
            MovieDataGenerator.ExportData(_movieListingDbContext.GetAllMovies());
            return(true);
        }