public static void EnsureSeedDataForContext(this TripInfoContext context) { if (context.Trips.Any()) { return; } // init seed data var trips = new List <Trip>() { new Trip() { Name = "New York City", Description = "The one with that big park.", PointsOfInterest = new List <PointsOfInterest>() { new PointsOfInterest() { Name = "Central Park", Description = "The most visited urban park in the United States." }, new PointsOfInterest() { Name = "Empire State Building", Description = "A 102-story skyscraper located in Midtown Manhattan." }, } }, new Trip() { Name = "Antwerp", Description = "The one with the cathedral that was never really finished.", PointsOfInterest = new List <PointsOfInterest>() { new PointsOfInterest() { Name = "Cathedral", Description = "A Gothic style cathedral, conceived by architects Jan and Pieter Appelmans." }, new PointsOfInterest() { Name = "Antwerp Central Station", Description = "The the finest example of railway architecture in Belgium." }, } }, new Trip() { Name = "Paris", Description = "The one with that big tower.", PointsOfInterest = new List <PointsOfInterest>() { new PointsOfInterest() { Name = "Eiffel Tower", Description = "A wrought iron lattice tower on the Champ de Mars, named after engineer Gustave Eiffel." }, new PointsOfInterest() { Name = "The Louvre", Description = "The world's largest museum." }, } } }; context.Trips.AddRange(trips); context.SaveChanges(); }
public TripInfoRepository(TripInfoContext context) { _context = context; }
// 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, TripInfoContext tripInfoContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); loggerFactory.AddNLog(); //loggerFactory.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } tripInfoContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Entities.Trip, Models.TripWithoutPointsOfInterestDto>(); cfg.CreateMap <Entities.Trip, Models.TripDto>(); cfg.CreateMap <Entities.PointsOfInterest, Models.PointsOfInterestDto>(); cfg.CreateMap <Models.PointsOfInterestCreatorDto, Entities.PointsOfInterest>(); cfg.CreateMap <Models.TripWithPointsOfInterestCreatorDto, Entities.Trip>(); cfg.CreateMap <Models.PointsOfInterestUpdaterDto, Entities.PointsOfInterest>(); cfg.CreateMap <Models.TripUpdaterDto, Entities.Trip>(); cfg.CreateMap <Entities.PointsOfInterest, Models.PointsOfInterestUpdaterDto>(); }); app.UseMvc(); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); }
public DummyController(TripInfoContext ttx) { _ttx = ttx; }