public static void EnsureSeedDatabaseForContext(this CityDbContext context) { if (context.City.Any()) { return; } var Cities = new List <City>() { new City() { Name = "Paris", Description = "The big iron tower in the middle", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Effel Tower", Description = "Old Iron Tower in the middle of city" }, new PointOfInterest() { Name = "Seine River", Description = "The Seine (/seɪn/ SAYN; French: La Seine, pronounced [la sɛːn]) is a 777-kilometre-long (483 mi) river and an important commercial waterway within the Paris Basin in the north of France." } } }, new City() { Name = "Los Angeles", Description = "The yellow long bridge", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Golden Bridge", Description = "Long Nice Bridge" } } } }; context.City.AddRange(Cities); context.SaveChanges(); }
public CityController(CityDbContext context) { _context = context; }
public TestDatabaseController(CityDbContext cityDbContext) { CityDbContext = cityDbContext; }
private readonly CityDbContext _cityDbContext; // Concrete type public CityRepository(CityDbContext dbContext) { _cityDbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }
public CityService(CityDbContext dbContext) { _dbContext = dbContext; }
public HomeController(CityDbContext db) { _db = db; }
// 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, CityDbContext cityDbContext) { env.ConfigureNLog("nlog.config"); //add NLog to ASP.NET Core loggerFactory.AddNLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } cityDbContext.EnsureSeedDataForContext(); //to show http status code in browser app.UseStatusCodePages(); app.UseMvc(); AutoMapper.Mapper.Initialize(config => { config.CreateMap <Entity.City, Models.CityWithoutPointsOfInterestVM>(); config.CreateMap <Entity.City, Models.CityVM>(); config.CreateMap <Entity.PointsOfInterest, Models.PointsOfInterestVM>(); config.CreateMap <Models.CityWithoutPointsOfInterestVM, Entity.PointsOfInterest>(); config.CreateMap <Entity.PointsOfInterest, Models.CreateUpdateCityOrPointsOfInterestVM>(); config.CreateMap <Models.CreateUpdateCityOrPointsOfInterestVM, Entity.City>(); config.CreateMap <Entity.City, Models.CreateUpdateCityOrPointsOfInterestVM>(); }); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); }
public DummyController(CityDbContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
public CitiesController(CityDbContext cityDbContext) { _cityDbContext = cityDbContext; }
public CityHub(CityDbContext cityDbContext) { this._cityDbContext = cityDbContext; }
public CityRepository(CityDbContext _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, CityDbContext cityDbContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); cityDbContext.EnsureSeedDatabaseForContext(); app.UseMvc(); // app.Run(async (context) => // { // await context.Response.WriteAsync("Hello World!"); // }); }