Exemplo n.º 1
0
 public Task Invoke(HttpContext httpContext, HotelContext db)
 {
     if (!(httpContext.Session.Keys.Contains("starting")))
     {
         InitializeDB.Initialize(db);
         httpContext.Session.SetString("starting", "Yes");
     }
     return(_next.Invoke(httpContext));
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <MarcetContext>();
                    InitializeDB.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            InitializeDB.Initialize(context);
        }
Exemplo n.º 4
0
        public RepositoryTests()
        {
            _newMovie = new Movie
            {
                Cast        = "Mock",
                Description = "Mock",
                Director    = "Mocking Director",
                Favourite   = true,
                IMDBRating  = 1,
                MovieId     = Guid.Parse("11111111-1111-1111-1111-111111111111"),
                Name        = "Mock Movie",
                Year        = DateTime.Now
            };

            var options = new DbContextOptionsBuilder <MovieContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            _movieContext = new MovieContext(options);

            _movieContext.Database.EnsureCreated();

            InitializeDB.Initialize(_movieContext);

            _repository = new Repository <Movie>(_movieContext);
        }