protected override async Task <PermissionResult> CanDeleteAsync(Organization value)
        {
            if (!String.IsNullOrEmpty(value.StripeCustomerId) && !User.IsInRole(AuthorizationRoles.GlobalAdmin))
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it has a subscription.", value.Id));
            }

            var projects = (await _projectRepository.GetByOrganizationIdAsync(value.Id)).Documents.ToList();

            if (!User.IsInRole(AuthorizationRoles.GlobalAdmin) && projects.Any())
            {
                return(PermissionResult.DenyWithMessage("An organization cannot be deleted if it contains any projects.", value.Id));
            }

            return(await base.CanDeleteAsync(value));
        }
        protected virtual async Task <PermissionResult> CanAddAsync(TModel value)
        {
            var orgModel = value as IOwnedByOrganization;

            if (_isOrganization || orgModel == null)
            {
                return(PermissionResult.Allow);
            }

            if (!CanAccessOrganization(orgModel.OrganizationId))
            {
                return(PermissionResult.DenyWithMessage("Invalid organization id specified."));
            }

            return(PermissionResult.Allow);
        }
        protected override async Task <PermissionResult> CanAddAsync(Project value)
        {
            if (String.IsNullOrEmpty(value.Name))
            {
                return(PermissionResult.DenyWithMessage("Project name is required."));
            }

            if (!await IsProjectNameAvailableInternalAsync(value.OrganizationId, value.Name))
            {
                return(PermissionResult.DenyWithMessage("A project with this name already exists."));
            }

            if (!await _billingManager.CanAddProjectAsync(value))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add additional projects."));
            }

            return(await base.CanAddAsync(value));
        }
        protected override async Task <PermissionResult> CanAddAsync(Organization value)
        {
            if (String.IsNullOrEmpty(value.Name))
            {
                return(PermissionResult.DenyWithMessage("Organization name is required."));
            }

            if (!await IsOrganizationNameAvailableInternalAsync(value.Name))
            {
                return(PermissionResult.DenyWithMessage("A organization with this name already exists."));
            }

            if (!await _billingManager.CanAddOrganizationAsync(CurrentUser))
            {
                return(PermissionResult.DenyWithPlanLimitReached("Please upgrade your plan to add an additional organization."));
            }

            return(await base.CanAddAsync(value));
        }