Ejemplo n.º 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, Seeding seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                seed.Seed();
            }

            app.UseHttpsRedirection();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Projeto Quiver");
            });

            app.UseRouting();

            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Word>()
            .Property(x => x.Id).ValueGeneratedOnAdd();
            modelBuilder.Entity <Word>()
            .HasIndex(x => x.Name).IsUnique();


            modelBuilder.Entity <Example>()
            .Property(x => x.Id).ValueGeneratedOnAdd();

            modelBuilder.Entity <User>()
            .Property(x => x.Id).ValueGeneratedOnAdd();

            modelBuilder.Entity <WordExample>()
            .HasKey(x => new { x.WordId, x.ExampleId });

            modelBuilder.Entity <WordExample>()
            .HasOne(x => x.Word)
            .WithMany(x => x.Examples)
            .HasForeignKey(x => x.WordId);

            modelBuilder.Entity <WordExample>()
            .HasOne(x => x.Example)
            .WithMany(x => x.Words)
            .HasForeignKey(x => x.ExampleId);

            Seeding.Seed(modelBuilder);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services        = scope.ServiceProvider;
                var serviceProvider = services.GetRequiredService <IServiceProvider>();
                var service         = scope.ServiceProvider.GetRequiredService <Context>();
                Seeding.MigrateDatabase(service);
                Seeding.Seed(serviceProvider).Wait();
            }

            host.Run();
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()){
                var services = scope.ServiceProvider;
                try{
                    var context = services.GetRequiredService <DataContext>();
                    context.Database.Migrate();
                    Seeding.Seed(context);
                } catch (Exception e) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, $"Error occured migrating DB");
                }
            }
            host.Run();
        }