Ejemplo n.º 1
0
        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;
 }
Ejemplo n.º 3
0
 public TestDatabaseController(CityDbContext cityDbContext)
 {
     CityDbContext = cityDbContext;
 }
Ejemplo n.º 4
0
        private readonly CityDbContext _cityDbContext; // Concrete type

        public CityRepository(CityDbContext dbContext)
        {
            _cityDbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
        }
Ejemplo n.º 5
0
 public CityService(CityDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 6
0
 public HomeController(CityDbContext db)
 {
     _db = db;
 }
Ejemplo n.º 7
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, 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!");
            //});
        }
Ejemplo n.º 8
0
 public DummyController(CityDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Ejemplo n.º 9
0
 public CitiesController(CityDbContext cityDbContext)
 {
     _cityDbContext = cityDbContext;
 }
Ejemplo n.º 10
0
 public CityHub(CityDbContext cityDbContext)
 {
     this._cityDbContext = cityDbContext;
 }
Ejemplo n.º 11
0
 public CityRepository(CityDbContext _context)
 {
     context = _context;
 }
Ejemplo n.º 12
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, 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!");
            // });
        }