Example #1
0
        public SystemControllerRepository(TenantInfo tenantInfo, IDataProtectionProvider provider)
        {
            this.tenantInfo = tenantInfo ?? throw new ArgumentNullException(nameof(tenantInfo));
            var optionsBuilder = new DbContextOptionsBuilder <NextAppContext>();

            optionsBuilder.UseNpgsql("Server=127.0.0.1;Port=5432;Database=arkdefence;User Id=postgres;Password=BmHkYi5436!;");//TODO dynamic
            this.context  = new NextAppContext(tenantInfo, optionsBuilder.Options);
            this.provider = provider ?? throw new ArgumentNullException(nameof(provider));
            protector     = provider.CreateProtector("App.v1");//TODO dynamic protector
        }
        public async Task <ICollection <Terminal> > GetAllAsync()
        {
            var hostTenant = await context.TryGetAsync("tenant-host").ConfigureAwait(false);

            var optionsBuilder = new DbContextOptionsBuilder <NextAppContext>();

            optionsBuilder.UseNpgsql(hostTenant.ConnectionString);
            var db = new NextAppContext(hostTenant, optionsBuilder.Options);

            return(await db.Terminals.ToArrayAsync());
        }
        public async void Add(Terminal terminal)
        {
            var hostTenant = await context.TryGetAsync("tenant-host").ConfigureAwait(false);

            var optionsBuilder = new DbContextOptionsBuilder <NextAppContext>();

            optionsBuilder.UseNpgsql(hostTenant.ConnectionString);
            var db = new NextAppContext(hostTenant, optionsBuilder.Options);

            //TODO validation
            db.EnsureAutoHistory();
            db.Terminals.Add(terminal);
            await db.SaveChangesAsync();
        }