Exemple #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);
        }
        public async Task <IActionResult> Post([FromBody] CreateControllerDto value)
        {
            var  tenantInfo = HttpContext.GetMultiTenantContext().TenantInfo;
            var  repo       = new SystemControllerRepository(tenantInfo, provider);
            bool res        = await repo.Add(value);

            if (!res)
            {
                throw new HttpResponseException()
                      {
                          Status = 403
                      };
            }
            return(Ok());
        }