コード例 #1
0
        public async Task <List <Client> > GetListAsync(string tenantSlug, User user)
        {
            var tenant = await _tenantService.CheckPermissionAsync(user, tenantSlug);

            return(await _dbContext.Clients
                   .Include(item => item.User)
                   .Where(item => item.TenantId == tenant.Id).ToListAsync());
        }
コード例 #2
0
        public async Task DeleteAsync(int id, User user)
        {
            var category = await GetAsync(id);

            if (category is null)
            {
                throw new RecordNotFoundException($"Category {id} not found");
            }

            await _tenantService.CheckPermissionAsync(user, category.Tenant.Slug);

            _dbContext.ProductCategories.Remove(category);

            await _dbContext.SaveChangesAsync();
        }
コード例 #3
0
        // I tried my best to not let this become a thing but my best simply wasn't good enough
        // Atharva asked for it and Paulchrisluke signed off on it
        public async Task <ActionResult <bool> > DoesUserOwnTenant(string tenantSlug)
        {
            var user = await _userManager.GetUserAsync(User);

            var tenant = await _tenantService.CheckPermissionAsync(user, tenantSlug);

            return(Ok(tenant != null));
        }
コード例 #4
0
        private async Task <Client> ValidateAsync(User user, int clientId)
        {
            var client = await _dbContext.Clients
                         .Include(item => item.Notes)
                         .FirstOrDefaultAsync(item => item.Id == clientId);

            if (client is null)
            {
                throw new RecordNotFoundException($"client {clientId} not found");
            }

            await _tenantService.CheckPermissionAsync(user, client.TenantId);

            return(client);
        }