Esempio n. 1
0
        private void Seed()
        {
            using var context = new DroneDbContext(ContextOptions);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var usuario = Usuario.Criar("test", "*****@*****.**", -23.35566, -46.36554, UsuarioRole.Cliente);

            usuario.AdicionarPassword("123");
            usuario.AdicionarRefreshToken("refreshtoken", DateTime.Now.AddDays(1));
            context.Add(usuario);

            var drone1 = Drone.Criar(12000, 3, 35, 100, DroneStatus.Livre);
            var drone2 = Drone.Criar(10000, 4, 35, 50, DroneStatus.Livre);

            context.Add(drone1);
            context.Add(drone2);

            context.SaveChanges();


            var pedido = Pedido.Criar(Guid.NewGuid(), 5000, 1000, usuario);

            var mongoContext = new DroneMongoDbContext(MongoOptions);

            mongoContext.Pedidos.InsertOne(pedido);
        }
Esempio n. 2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DroneDbContext context, IPasswordHasher <Usuario> passwordHasher, IGeradorToken geradorToken)
        {
            app.UseMiddleware(typeof(ErrorHandlerMiddleware));
            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
            }


            app.UseHttpsRedirection();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Drone Delivery Entrega V1");
                c.RoutePrefix = string.Empty;
            });

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            Seed.Seed.SeedData(context, passwordHasher, geradorToken);
        }
 public UnitOfWork(DroneDbContext context)
 {
     _context = context;
     Pedidos  = new PedidoRepository(_context);
     Drones   = new DroneRepository(_context);
     Usuarios = new UsuarioRepository(_context);
 }
Esempio n. 4
0
        public UnitOfWork(DroneDbContext context, DroneMongoDbContext contextMongo)
        {
            _context      = context;
            _contextMongo = contextMongo;

            Pedidos  = new PedidoRepository(_context, _contextMongo);
            Drones   = new DroneRepository(_context, _contextMongo);
            Usuarios = new UsuarioRepository(_context);
        }
Esempio n. 5
0
        public static void SeedData(DroneDbContext context, IPasswordHasher <Usuario> passwordHasher, IGeradorToken geradorToken)
        {
            var admin = context.Usuarios.FirstOrDefault(x => (int)x.Role == (int)UsuarioRole.Admin);

            if (admin == null)
            {
                admin = Usuario.Criar("Admin", "*****@*****.**", -23.5753639, -46.645421, UsuarioRole.Admin);
                var passwordHash = passwordHasher.HashPassword(admin, "123");
                admin.AdicionarPassword(passwordHash);

                var token = geradorToken.GerarRefreshToken(admin);
                admin.AdicionarRefreshToken(token.Token, token.DataExpiracao);

                context.Usuarios.Add(admin);
                context.SaveChanges();
            }
        }
Esempio n. 6
0
 public DroneRepository(DroneDbContext context, DroneMongoDbContext contextMongo)
 {
     _context      = context;
     _contextMongo = contextMongo;
 }
Esempio n. 7
0
 public DroneRepositoryTests()
 {
     _context         = new DroneDbContext(ContextOptions);
     _droneRepository = new DroneRepository(_context);
 }
Esempio n. 8
0
 public PedidoRepository(DroneDbContext dbContext)
 {
     _context = dbContext;
 }
 public PedidoRepositoryTests()
 {
     _context          = new DroneDbContext(ContextOptions);
     _pedidoRepository = new PedidoRepository(_context);
 }
Esempio n. 10
0
 public UsuarioRepositoryTests()
 {
     _context           = new DroneDbContext(ContextOptions);
     _usuarioRepository = new UsuarioRepository(_context);
 }
Esempio n. 11
0
 public PedidoRepositoryTests()
 {
     _context          = new DroneDbContext(ContextOptions);
     _contextMongo     = new DroneMongoDbContext(MongoOptions);
     _pedidoRepository = new PedidoRepository(_context, _contextMongo);
 }
Esempio n. 12
0
 public DroneRepository(DroneDbContext context)
 {
     _context = context;
 }
Esempio n. 13
0
 public UsuarioRepository(DroneDbContext context)
 {
     _context = context;
 }
 public IntinerarioRepository(DroneDbContext context)
 {
     _context = context;
 }