public CitiesService(CitiesDbContext context) { _context = context; }
public DummyController(CitiesDbContext ctx) { _ctx = ctx; }
public CityRepository(CitiesDbContext context) { _context = context; }
public static void EnsureSeedDataForContext(this CitiesDbContext context) { if (context.Cities.Any()) { return; } // init seed data var cities = new List <City>() { new City() { Name = "New York City", Description = "The one with that big park.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Central Park", Description = "The most visited urban park in the United States." }, new PointOfInterest() { Name = "Empire State Building", Description = "A 102-story skyscraper located in Midtown Manhattan." }, } }, new City() { Name = "Antwerp", Description = "The one with the cathedral that was never really finished.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Cathedral", Description = "A Gothic style cathedral, conceived by architects Jan and Pieter Appelmans." }, new PointOfInterest() { Name = "Antwerp Central Station", Description = "The the finest example of railway architecture in Belgium." }, } }, new City() { Name = "Paris", Description = "The one with that big tower.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Eiffel Tower", Description = "A wrought iron lattice tower on the Champ de Mars, named after engineer Gustave Eiffel." }, new PointOfInterest() { Name = "The Louvre", Description = "The world's largest museum." }, } } }; context.Cities.AddRange(cities); context.SaveChanges(); }
// 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, CitiesDbContext citiesDbContext) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //loggerFactory.AddProvider(new NLogLoggerProvider()); loggerFactory.AddNLog(); citiesDbContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); AutoMapper.Mapper.Initialize(config => { config.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>(); config.CreateMap <Entities.City, Models.CityDto>(); config.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>(); config.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>(); config.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>(); config.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>(); }); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(ILoggerFactory loggerFactory, IApplicationBuilder app, IHostingEnvironment env, CitiesDbContext context) { loggerFactory.AddNLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } context.EnsureSeedDataForContext(); if (env.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; }); } AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Entities.City, Models.CityWithoutPointsOfInterestDto>().ReverseMap(); cfg.CreateMap <Entities.City, Models.CityDTO>().ReverseMap(); cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDTO>().ReverseMap(); cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>().ReverseMap(); cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>().ReverseMap(); cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>().ReverseMap(); }); app.UseMvc(); }