Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, Entities.CityInfoContext cityInfoContext
                              )
        {
            // Next 2 lines does same thing
            //loggerFactory.AddProvider(new NLog.Extensions.Logging.NLogLoggerProvider());
            loggerFactory.AddNLog();

            // Middleware for development env only
            if (env.IsDevelopment())
            {
                // Middleware that handles exception
                app.UseDeveloperExceptionPage();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg => {
                // Map From name to same name
                // ignore variables that doesnt exists
                cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>();
                cfg.CreateMap <Entities.City, Models.CityDto>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Example #2
0
        public static void SeedDataToCityInfoContext(this CityInfoContext context)
        {
            if (context.Cities.Any())
            {
                return;
            }

            var cities = new List <City>()
            {
                new City()
                {
                    Name             = "New York",
                    Description      = "The one with the big park",
                    PointsOfInterest = new List <PointsOfInterest>()
                    {
                        new PointsOfInterest()
                        {
                            Name        = "Central park",
                            Description = "The most visit urban park visit in the USA"
                        },
                        new PointsOfInterest()
                        {
                            Name        = "Empire state building",
                            Description = "A 102-story skyscraper"
                        }
                    }
                },
                new City()
                {
                    Name             = "Antwerp", Description = "The one with a cathedral that was never really finished",
                    PointsOfInterest = new List <PointsOfInterest>()
                    {
                        new PointsOfInterest()
                        {
                            Name        = "Central park",
                            Description = "The most visit urban park visit in the USA"
                        },
                        new PointsOfInterest()
                        {
                            Name        = "Empire state building",
                            Description = "A 102-story skyscraper"
                        }
                    }
                },
                new City()
                {
                    Name             = "Paris", Description = "The one with the big tower",
                    PointsOfInterest = new List <PointsOfInterest>()
                    {
                        new PointsOfInterest()
                        {
                            Name        = "Central park",
                            Description = "The most visit urban park visit in the USA"
                        },
                        new PointsOfInterest()
                        {
                            Name        = "Empire state building",
                            Description = "A 102-story skyscraper"
                        }
                    }
                },
            };

            context.Cities.AddRange(cities);
            context.SaveChanges();
        }