コード例 #1
0
        public static void DataSeed(this CoditoContext context)
        {
            if (context.Cars.Any())
            {
                return;
            }

            var cars = new List <Car>
            {
                new Car
                {
                    Brand       = "Volkswagen",
                    Model       = "Tiguan",
                    BodyType    = CarBodyType.SUV,
                    Description = "Volkswagen's SUV model."
                },
                new Car
                {
                    Brand       = "Skoda",
                    Model       = "Octavia Combi",
                    BodyType    = CarBodyType.Break,
                    Description = "Skoda's most popular break."
                }
            };

            cars[0].Customizations.Add(new Customization
            {
                NumberSold     = 5,
                Name           = "Tiguan Trendline",
                Url            = "https://fake-url.com",
                InventoryLevel = 4
            });
            cars[0].Customizations.Add(new Customization
            {
                NumberSold     = 3,
                Name           = "Tiguan Comfortline",
                Url            = "https://fake-url.com",
                InventoryLevel = 4
            });
            cars[1].Customizations.Add(new Customization
            {
                NumberSold     = 3,
                Name           = "Octavia Combi RS",
                Url            = "https://fake-url.com",
                InventoryLevel = 8
            });
            cars[1].Customizations.Add(new Customization
            {
                NumberSold     = 4,
                Name           = "Octavia Combi Scout",
                Url            = "https://fake-url.com",
                InventoryLevel = 6
            });

            context.Cars.AddRange(cars);
            context.SaveChanges();
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CoditoContext coditoContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // Seed DB
            coditoContext.DataSeed();

            // Configure API
            app.UseHttpsRedirection();
            app.UseExceptionHandlerWithProblemJson();
            app.UseStatusCodePagesWithReExecute("/errors/{0}");
            app.UseMvc();
            app.UseOpenApi();
            // Configure Automapper
            AutoMapperConfig.Initialize();
        }
コード例 #3
0
 public CoditoRepository(CoditoContext coditoContext)
 {
     _coditoContext = coditoContext;
 }