Exemplo n.º 1
0
        public async Task AddAsync(RolePermissions entity)
        {
            await DbContextManager.BeginTransactionAsync();

            var spParameters = new SqlParameter[1];

            spParameters[0] = new SqlParameter()
            {
                ParameterName = "RolePermissions", Value = entity.ToString()
            };
            var result = await DbContextManager.StoreProc <RolePermissions>("[dbo].[spRolePermissionAdd]", spParameters);
        }
Exemplo n.º 2
0
        public bool IsRoleHavePermission(string roleName, RolePermissions permission)
        {
            Task <ApplicationRole> task = _roleManager.FindByNameAsync(roleName);
            ApplicationRole        role = task.Result;

            if (role == null)
            {
                throw new InvalidOperationException($"There is no '{roleName}' role in database");
            }

            DBContext.Entry(role).Collection(r => r.RolePermissions).Load();

            List <PermissionEntity> permissions = new List <PermissionEntity>();

            foreach (var rp in role.RolePermissions)
            {
                DBContext.Entry(rp).Reference(i => i.Permission).Load();
                permissions.Add(rp.Permission);
            }

            return(permissions.Any(p => p.Permission == permission.ToString()));
        }
Exemplo n.º 3
0
 public async Task RemovePermissionFromRoleAsync(string roleName, RolePermissions permission)
 {
     await RemovePermissionFromRoleAsync(roleName, permission.ToString());
 }
Exemplo n.º 4
0
 /// <summary>
 /// Adds permission to role
 /// </summary>
 public async Task AddPermissionToRoleAsync(string roleName, RolePermissions permission)
 {
     await AddPermissionToRoleAsync(roleName, permission.ToString());
 }
Exemplo n.º 5
0
 public static bool IsInPermission(this ClaimsPrincipal cp, RolePermissions permission)
 {
     return(cp.HasClaim("PermissionClaim", permission.ToString()));
 }