Exemple #1
0
        private void ConfigureServices(IServiceCollection services, string connectionString)
        {
            var options   = new DbContextOptionsBuilder <PostgresDbContext>().UseNpgsql().Options;
            var dbContext = new PostgresDbContext(connectionString, options);

            services.AddSingleton <IUnitOfWork>(s => new UnitOfWork(
                                                    dbContext,
                                                    new ChildRepository(dbContext),
                                                    new GroupRepository(dbContext),
                                                    new ChildChosenDaysRepository(dbContext))
                                                );

            services.AddScoped <IChildFacadeAsync, ChildFacadeAsync>(s => new ChildFacadeAsync(s));

            services.AddScoped <IChildFacade, ChildFacade>(s => new ChildFacade(s));

            services.AddScoped <IGroupFacade, GroupFacade>(s => new GroupFacade(
                                                               s.GetRequiredService <IUnitOfWork>()));

            services.AddTransient <IChildAsyncService, ChildAsyncService>(s => new ChildAsyncService(
                                                                              s.GetRequiredService <IUnitOfWork>()));

            services.AddTransient <IGroupAsyncService, GroupAsyncService>(s => new GroupAsyncService(s));

            services.AddTransient <IChildService, ChildService>(s => new ChildService(
                                                                    s.GetRequiredService <IUnitOfWork>()));

            services.AddTransient <IGroupService, GroupService>(s => new GroupService(s));
        }
Exemple #2
0
        public void Postgre_Context_Test()
        {
            BaseDbContext postgreContext = new PostgresDbContext();
            var           mov            = postgreContext.Movies.First(x => x.MovieId == 3);

            mov.Title.Should().Be("Terminator");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // use standard EF API Context
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <PostgresDbContext, Configuration>());

            using (var ctx = new PostgresDbContext())
            {
                var tournament = new Tournament()
                {
                    Name = "Roland Garros"
                };
                ctx.Tournaments.Add(tournament);
                ctx.SaveChanges();

                var id = ctx.Tournaments.Where(t => t.Name == "Roland Garros").Select(n => n.Id).FirstOrDefault();
                Console.WriteLine("Tournament Id: " + id);


                for (int i = 0; i < 10; i++)
                {
                    var ticket = new Ticket()
                    {
                        Sector       = Sector.Front,
                        Price        = 5.40m,
                        Number       = 200,
                        TournamentId = id
                    };
                    ctx.Tickets.Add(ticket);
                }
                ctx.SaveChanges();

                var list = ctx.Tickets.Select(t => t.Tournament).ToList();
                Console.WriteLine(String.Join(", ", list));
            }
        }
Exemple #4
0
 public ConductorController(ICuentaUsuarioDomainService cuentaUsuarioService, IUsuarioDomainService usuarioService, ITipoCuentaDomainService tipoCuentaService,
                            IDocumentoDomainService documentoService, ITipoDocumentoDomainService tipoDocumentoService, IMapper mapper, PostgresDbContext context)
 {
     _usuarioService       = usuarioService;
     _cuentaUsuarioService = cuentaUsuarioService;
     _tipoCuentaService    = tipoCuentaService;
     _documentoService     = documentoService;
     _tipoDocumentoService = tipoDocumentoService;
     _mapper  = mapper;
     _baseUrl = string.Empty;
     _context = context;
 }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddSingleton(Configuration);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient <IDapperContext>(p =>
            {
                var connection = PostgresConnection
                                 .Init()
                                 .SetarHost("localhost")
                                 .SetarUsuario("postgres")
                                 .SetarSenha("postgres")
                                 .SetarNomeBaseDeDados("bdgomi")
                                 .SetarPorta(5433)
                                 .Criar();

                if (!_iniciouBancoDados)
                {
                    var dbContext = new PostgresDbContext(connection);
                    dbContext.CreateDatabaseAsync(Assembly.GetAssembly(typeof(Versao))).Wait();
                    dbContext.ExecutarScriptsDaVersao();
                    _iniciouBancoDados = true;
                }

                return(new PostgresDbContext(connection));
            });

            services.AddTransient <ICaixaRepository, CaixaRepository>();
            services.AddTransient <ICentroCustoRepository, CentroCustoRepository>();
            services.AddTransient <IContaRepository, ContaRepository>();
            services.AddTransient <IEmpresaRepository, EmpresaRepository>();
            services.AddTransient <IPagarRepository, PagarRepository>();
            services.AddTransient <IPessoaRepository, PessoaRepository>();
            services.AddTransient <IPlanoContaRepository, PlanoContaRepository>();
            services.AddTransient <IReceberRepository, ReceberRepository>();
            services.AddTransient <ITransferenciaRepository, TransferenciaRepository>();
            services.AddTransient <IUsuarioRepository, UsuarioRepository>();

            services.AddSingleton <ICaixaService, CaixaService>();
            services.AddSingleton <ICentroCustoService, CentroCustoService>();
            services.AddSingleton <IContaService, ContaService>();
            services.AddSingleton <IDashboardService, DashboardService>();
            services.AddSingleton <IEmpresaService, EmpresaService>();
            services.AddSingleton <IPagarService, PagarService>();
            services.AddSingleton <IPessoaService, PessoaService>();
            services.AddSingleton <IPlanoContaService, PlanoContaService>();
            services.AddSingleton <IReceberService, ReceberService>();
            services.AddSingleton <ITransferenciaService, TransferenciaService>();
            services.AddSingleton <IUsuarioService, UsuarioService>();
            services.AddTransient <IPessoaService, PessoaService>();
        }
 public static IDbFactory GetCurrentDatabase(object configs)
 {
     if (Constants.CURRENT_DATABASE == DbSetting.Postgres)
     {
         var mongoConnector = new MongodbConnector(configs);
         return(new MongodbFactory(mongoConnector));
     }
     else
     {
         var postgresContext = new PostgresDbContext(configs);
         return(new PostgresFactory(postgresContext));
     }
 }
Exemple #7
0
 /// <exception cref="T:System.Exception">Wrong provider</exception>
 public static IDatabaseProvider GetCurrentDbProvider(DbSettings dbProvider, object configs)
 {
     if (dbProvider == DbSettings.Postgres)
     {
         var mongoConnector = new MongodbConnector(configs);
         return(new MongodbProvider(mongoConnector));
     }
     else if (dbProvider == DbSettings.Mongodb)
     {
         var postgresContext = new PostgresDbContext(configs);
         return(new PostgresProvider(postgresContext));
     }
     else
     {
         throw new Exception("Wrong provider");
     }
 }
        static void Main(string[] args)
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder().UseLoggerFactory(LoggerFactory).UseNpgsql(_connectionString);

            using (PostgresDbContext ctx = new PostgresDbContext(optionsBuilder.Options))
            {
                //the conversion from provider is woking good
                var testQuery = ctx.TableEntity.FirstOrDefault(x => x.Item == "ACC");

                //this linq query works good
                var workingQuery = ctx.TableEntity.FirstOrDefault(x => x.HasCustomers == true);

                //this linq query don't work and throw a Npgsql.PostgresException 'argument of WHERE must be type boolean, not type character'
                var notWorkingQuery = ctx.TableEntity.FirstOrDefault(x => x.HasCustomers);
            }

            Console.ReadLine();
        }
Exemple #9
0
 public override void LoadEntity(Role t)
 {
     using (var dbContext = new PostgresDbContext())//ApplicationDbContext
     {
         foreach (var p in dbContext.Permissions)
         {
             if (t.RoleInPermissions.Any(a => a.PermissionId == p.Id))
             {
                 continue;
             }
             t.RoleInPermissions.Add(new RoleInPermission
             {
                 PermissionId = p.Id,
                 Permission   = p,
                 IsAccessible = false,
                 RoleId       = t.Id
             });
         }
     }
     base.LoadEntity(t);
     Name = t.GetCurrentLocale().Name;
 }
Exemple #10
0
 public Repository(PostgresDbContext context)
 {
     this.Context = context;
 }
 public CodigoValidacionRepository(PostgresDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #12
0
 public CuentaUsuarioRepository(PostgresDbContext context)
 {
     _context = context;
 }
Exemple #13
0
 public TipoCuentaRepository(PostgresDbContext context)
 {
     _context = context;
 }
Exemple #14
0
 public UnitOfWork(PostgresDbContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public ViajeConductorRepository(PostgresDbContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public MarcaRepository(PostgresDbContext context)
 {
     _context = context;
 }
 public ValuesController(PostgresDbContext context)
 {
     postgres = context;
 }
 public AuthController(IConfiguration configuration, PostgresDbContext postgresDbContext)
 {
     _configuration     = configuration;
     _postgresDbContext = postgresDbContext;
 }
Exemple #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public ModeloRepository(PostgresDbContext context)
 {
     _context = context;
 }
 public ChatConnection(WebSocketHandler handler, PostgresDbContext context) : base(handler)
 {
     //_vehiculoPosicionService = new  VehiculoPosicionService;
     _context = context;
 }
Exemple #21
0
        public void Configure(IApplicationBuilder app, IApplicationLifetime appLifetime, ILoggerFactory loggerFactory, PostgresDbContext dbContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCors("AllowAll");
            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "api/{controller=Home}/{action=Index}/{id?}"
                    );
            });

            DbInitializer.InitializePG(dbContext);

            appLifetime.ApplicationStopped.Register(() => _currentContainer.Dispose());
        }
Exemple #22
0
 public PaisRepository(PostgresDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public PostgreSqlDbRepository(PostgresDbContext context)
 {
     _context = context;
     Entities = _context.Set <TEntity>();
 }
 public UserRepository(PostgresDbContext context) : base(context)
 {
 }
Exemple #25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public ViajeUsuarioRepository(PostgresDbContext context)
 {
     _context = context;
 }
Exemple #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public VehiculoPosicionRepository(PostgresDbContext context)
 {
     _context = context;
 }
Exemple #27
0
 public ImagenRepository(PostgresDbContext context)
 {
     _context = context;
 }
Exemple #28
0
 public CategoryRepository(PostgresDbContext context)
     : base(context)
 {
 }
Exemple #29
0
 public MunicipioRepository(PostgresDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Contexto de base de datos</param>
 public EstatusViajeRepository(PostgresDbContext context)
 {
     _context = context;
 }