Exemple #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 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();
            });
        }
Exemple #2
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();
        }