示例#1
0
        public Task AddToRoleAsync(TUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentException("Argument cannot be null or empty: roleName.");
            }
            BusinessLogicLayer.Entity.RoleSecurity.Role role = new BusinessLogicLayer.Entity.RoleSecurity.Role(roleName);

            if (role != null)
            {
                BusinessLogicLayer.Entity.RoleSecurity.PersonRole prole = new BusinessLogicLayer.Entity.RoleSecurity.PersonRole();
                prole.PersonId = user.BusinessEntityId;
                prole.RoleId   = role.RoleId;
                prole.Save();
            }

            return(Task.FromResult <object>(null));
        }
示例#2
0
        public Task RemoveFromRoleAsync(TUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException("roleName");
            }
            BusinessLogicLayer.Entity.RoleSecurity.Role role = new BusinessLogicLayer.Entity.RoleSecurity.Role(roleName);
            if (role != null)
            {
                BusinessLogicLayer.Entity.RoleSecurity.PersonRole prole = new BusinessLogicLayer.Entity.RoleSecurity.PersonRole(role.RoleId, user.BusinessEntityId);
                if (prole != null)
                {
                    prole.Delete();
                }
            }


            return(Task.FromResult <Object>(null));
        }