コード例 #1
0
        public async Task <bool> Add(CreateControllerDto controller)
        {
            if (tenantInfo.Name != Host)
            {
                //throw new HttpResponseException() { Status = 403, Value = "Only Host allowed to add Controllers" };
                return(false);
            }
            var ClientIdHash     = protector.Protect(controller.ClientId);
            var ClientSecretHash = protector.Protect(controller.ClientSecret);
            //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);

            var newController = new SbcController(controller.ALias);

            newController.ClientIdHash     = ClientIdHash;
            newController.ClientSecretHash = ClientSecretHash;

            context.EnsureAutoHistory();
            context.Controllers.Add(newController);
            await context.SaveChangesAsync();

            return(true);
        }
コード例 #2
0
        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();
        }