Пример #1
0
        /// <summary>
        /// Delete all links between a role and extensions.
        /// </summary>
        /// <param name="storage_">Storage interface provided by services container.</param>
        /// <param name="roleManager_">Roles manager instance.</param>
        /// <param name="roleName_">Role name.</param>
        /// <returns>False if not data to delete found, otherwise true.</returns>
        internal static async Task <bool> DeleteRoleExtensionsLinksAsync(IStorage storage_, RoleManager <IdentityRole <string> > roleManager_, string roleName_)
        {
            string roleId = (await roleManager_.FindByNameAsync(roleName_))?.Id;

            if (string.IsNullOrEmpty(roleId))
            {
                return(false);
            }

            IRolePermissionRepository    repo    = storage_.GetRepository <IRolePermissionRepository>();
            IEnumerable <RolePermission> records = repo.FilteredByRoleId(roleId).ToList();

            if (!records.Any())
            {
                return(false);
            }

            foreach (var record in records)
            {
                repo.Delete(record.RoleId, record.Extension);
            }

            await storage_.SaveAsync();

            return(true);
        }