示例#1
0
        /// <summary>
        ///     Adds granular permissions to a user.
        /// </summary>
        public async Task AddUserGranularPermissions(GranularPermission granularPermission)
        {
            try
            {
                var stored = await GetUserGranularPermissions(granularPermission.Id);

                ValidatePermissionsForAdd(
                    granularPermission.AdditionalPermissions,
                    granularPermission.DeniedPermissions,
                    stored.AdditionalPermissions,
                    stored.DeniedPermissions);

                var allowPermsList = granularPermission.AdditionalPermissions.ToList();
                var denyPermsList  = granularPermission.DeniedPermissions.ToList();

                allowPermsList.AddRange(stored.AdditionalPermissions);
                denyPermsList.AddRange(stored.DeniedPermissions);

                granularPermission.AdditionalPermissions = allowPermsList;
                granularPermission.DeniedPermissions     = denyPermsList;
            }
            catch (NotFoundException <GranularPermission> )
            {
                ValidatePermissionsForAdd(
                    granularPermission.AdditionalPermissions,
                    granularPermission.DeniedPermissions,
                    null,
                    null);
            }

            await _permissionStore.AddOrUpdateGranularPermission(granularPermission);
        }
        /// <summary>
        ///     Adds granular permissions to a user.
        /// </summary>
        public async Task AddUserGranularPermissions(GranularPermission granularPermission)
        {
            try
            {
                var stored = await GetUserGranularPermissions(granularPermission.Id);

                granularPermission.AdditionalPermissions.ToList().AddRange(stored.AdditionalPermissions);
                granularPermission.DeniedPermissions.ToList().AddRange(stored.DeniedPermissions);
            }
            catch (NotFoundException <GranularPermission> )
            {
                // Do nothing
            }

            await _permissionStore.AddOrUpdateGranularPermission(granularPermission);
        }