Ejemplo n.º 1
0
        private async Task InitializeDb(MineraDbContext dbContext)
        {
            // IOptions<AppSettings> options = Options.Create(appSettings);

            dbContext.Database.EnsureCreated();

            // RelationalDatabaseCreator databaseCreator = (RelationalDatabaseCreator) dbContext.Database.GetService<IDatabaseCreator>();
            // databaseCreator.CreateTables();

            var userRepository = new UsuarioRepository(dbContext);

            var adminUser = await userRepository.GetUserByUsername("admin");

            if (adminUser == null)
            {
                // Create admin user
                string admin_password = "******";

                byte[] admin_passwordHash, admin_passwordSalt;

                UsuarioService.CreatePasswordHash(admin_password, out admin_passwordHash, out admin_passwordSalt);

                await userRepository.Create(new Usuario()
                {
                    nome          = "Administrador",
                    papel         = "admin",
                    username      = "******",
                    password_hash = admin_passwordHash,
                    password_salt = admin_passwordSalt
                });

                // Create automation user

                string client_password = "******";

                byte[] client_passwordHash, client_passwordSalt;

                UsuarioService.CreatePasswordHash(client_password, out client_passwordHash, out client_passwordSalt);

                await userRepository.Create(new Usuario()
                {
                    nome          = "Cliente Automação",
                    papel         = "client",
                    username      = "******",
                    password_hash = client_passwordHash,
                    password_salt = client_passwordSalt
                });
            }
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, MineraDbContext dbContext)
        {
            app.UseStaticFiles(new StaticFileOptions
            {
                ServeUnknownFileTypes = true,
                DefaultContentType    = "image/png"
            });

            loggerFactory.AddFile(Configuration.GetSection("Logging"));

            // InitializeDb(dbContext).Wait();
            // 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", "Minera API v1");
                c.RoutePrefix = string.Empty;
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseCors("CorsPolicy");

            app.UseAuthentication();

            app.ConfigureCustomExceptionMiddleware();
            app.UseHttpsRedirection();

            app.UseMvc();
        }
Ejemplo n.º 3
0
 public UsuarioRepository(MineraDbContext dbContext)
     : base(dbContext)
 {
 }
Ejemplo n.º 4
0
 public InsumoRepository(MineraDbContext dbContext)
     : base(dbContext)
 {
 }
Ejemplo n.º 5
0
 public ManutencaoRepository(MineraDbContext dbContext)
     : base(dbContext)
 {
 }
Ejemplo n.º 6
0
 public GenericRepository(MineraDbContext dbContext)
 {
     _dbContext = dbContext;
 }