Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedingData seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseStatusCodePagesWithRedirects("/Error/{0}");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseSession();
            app.UseAuthentication();
            app.UseAuthorization();
            seeder.SeedAdminUser();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <BuyOrder>().HasBaseType <Order>();
            modelBuilder.Entity <SellOrder>().HasBaseType <Order>();
            modelBuilder.Entity <OrderItem>().HasBaseType <Product>();

            //Seeding some data
            SeedingData.Seed(modelBuilder);
            base.OnModelCreating(modelBuilder);
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedingData seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                seed.SeedUsers();
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors();

            //Static files
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
                RequestPath  = new PathString("/Resources")
            });

            // Swagger Json documentation
            app.UseSwagger();

            //Allow request front end

            // Generate Page Swagger HTML
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("./swagger/v1/swagger.json", "Library Card API - v1");
                c.RoutePrefix = string.Empty;
            });

            //Swagger Page redirect
            var option = new RewriteOptions();

            option.AddRedirect("^&", "swagger");
            app.UseRewriter(option);

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            //.Run();
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <BookDbContext>();
                    SeedingData.Initializer(context);
                }
                catch (Exception EX)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(EX, "An error occured while deeding the database.");
                }
            }
            host.Run();
        }
Beispiel #5
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context            = services.GetRequiredService <DataContext>();
                var userManager        = services.GetRequiredService <UserManager <AppUser> >();
                var roleManager        = services.GetRequiredService <RoleManager <AppRole> >();
                var customerRepository = services.GetRequiredService <ICustomerRepository>();
                await context.Database.MigrateAsync();

                await SeedingData.SeedUsers(userManager, roleManager);

                await SeedingData.SeedCustomers(context, customerRepository);

                await SeedingData.SeedOwners(context);

                await SeedingData.SeedDeputies(context);

                await SeedingData.SeedBuildings(context);

                await SeedingData.SeedFloors(context);

                await SeedingData.SeedRooms(context);

                await SeedingData.SeedContracts(context);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "Error occured during migration");
            }

            await host.RunAsync();
        }
Beispiel #6
0
 protected override void Seed(ApplicationDbContext context)
 {
     SeedingData.SeedUsers2(context);
 }