Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DemoContext db)
        {
            CreateData(db);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 2
0
        private static void CreateData(DemoContext db)
        {
            db.Database.EnsureDeleted();
            db.Database.EnsureCreated();

            // add test data
            var shawshank = new Movie
            {
                Name     = "The Shawshank Redemption",
                Genre    = Genre.Drama,
                Released = new DateTime(1994, 10, 14),
                Rating   = 9.2,
                Director = new Person
                {
                    FirstName = "Frank",
                    LastName  = "Darabont",
                    Dob       = new DateTime(1959, 1, 28),
                }
            };

            shawshank.Actors = new List <Actor> {
                new Actor {
                    Person = new Person {
                        Dob       = new DateTime(1958, 10, 16),
                        FirstName = "Tim",
                        LastName  = "Robbins",
                    },
                },
            };
            db.Movies.Add(shawshank);
            var francis = new Person
            {
                Dob       = new DateTime(1939, 4, 7),
                FirstName = "Francis",
                LastName  = "Coppola",
            };
            var godfather = new Movie
            {
                Name     = "The Godfather",
                Genre    = Genre.Drama,
                Released = new DateTime(1972, 3, 24),
                Rating   = 9.2,
                Director = francis,
            };

            godfather.Actors = new List <Actor> {
                new Actor {
                    Person = new Person {
                        Dob       = new DateTime(1924, 4, 3),
                        Died      = new DateTime(2004, 7, 1),
                        FirstName = "Marlon",
                        LastName  = "Brando",
                    },
                },
                new Actor {
                    Person = new Person {
                        Dob       = new DateTime(1940, 4, 25),
                        FirstName = "Al",
                        LastName  = "Pacino",
                    },
                },
            };
            godfather.Writers = new List <Writer> {
                new Writer {
                    Person = francis,
                }
            };

            db.Movies.Add(godfather);

            db.SaveChanges();
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IServiceCollection loggerFactory, DemoContext db)
        {
            //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddDebug();
            ConfigureLogging(loggerFactory);

            CreateData(db);

            app.UseFileServer();

            app.UseMvc();
        }