Ejemplo n.º 1
0
        /// <summary>
        /// Retorna uma lista de Roles do Usuário em questão
        /// </summary>
        /// <param name="userId">Código do Usuário</param>
        /// <returns></returns>
        public List <string> FindByUserId(Guid userId)
        {
            List <string> roles = new List <string>();
            //TODO: This probably does not work, and may need testing.

            string commandText = "select AspRoles." + RoleTable.fieldName.Quoted() + " from " + UserTable <IdentityUser> .fullTableName + " AspUsers" +
                                 " INNER JOIN " + fullTableName + " AspUserRoles " +
                                 " ON AspUsers." + UserTable <IdentityUser> .FieldId.Quoted() + " = AspUserRoles." + fieldUserID.Quoted() +
                                 " INNER JOIN " + RoleTable.fullTableName + " AspRoles " +
                                 " ON AspUserRoles." + fieldRoleID.Quoted() + " = AspRoles." + RoleTable.fieldId.Quoted() +
                                 " where AspUsers." + UserTable <IdentityUser> .FieldId.Quoted() + " = @userId";

            /*select AspNetRoles.Name from AspNetUsers
             * inner join AspNetUserRoles
             * ON AspNetUsers.ID = AspNetUserRoles.UserID
             * inner join AspNetRoles
             * ON aspNetUserRoles.RoleID = AspNetRoles.ID
             * where AspNetUser.ID = :id
             */

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@userId", userId);

            var rows = _database.ExecuteQuery(commandText, parameters);

            foreach (var row in rows)
            {
                roles.Add(row[RoleTable.fieldName]);
            }

            return(roles);
        }
Ejemplo n.º 2
0
        public IList <IdentityUser> GetUsersInRole(string roleName)
        {
            string commandText = "SELECT * FROM " + fullTableName + " WHERE " +
                                 fieldName.Quoted() + "  = @Name";

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("Name", roleName);

            var rows = _database.ExecuteQuery(commandText, parameters);
            var list = rows.Select(UserTable <IdentityUser> .loadUser).ToList();

            return(list);
        }
        public List <TUser> GetUsers()
        {
            string commandText = "SELECT * FROM " + fullTableName;
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            var rows = _database.ExecuteQuery(commandText, parameters);
            var list = rows.Select(loadUser).ToList();

            return(list);
        }
        /// <summary>
        /// Returns a ClaimsIdentity instance given a userId.
        /// </summary>
        /// <param name="userId">The user's id.</param>
        /// <returns></returns>
        public ClaimsIdentity FindByUserId(Guid userId)
        {
            ClaimsIdentity claims                  = new ClaimsIdentity();
            string         commandText             = "SELECT * FROM " + fullTableName + " WHERE " + fieldUserID.Quoted() + " = @userId";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "userId", userId }
            };

            var rows = _database.ExecuteQuery(commandText, parameters);

            foreach (var row in rows)
            {
                Claim claim = new Claim(row[fieldClaimType], row[fieldClaimValue]);
                claims.AddClaim(claim);
            }

            return(claims);
        }
        /// <summary>
        /// Returns a list of user's logins.
        /// </summary>
        /// <param name="userId">The user's id.</param>
        /// <returns></returns>
        public List <UserLoginInfo> FindByUserId(Guid userId)
        {
            List <UserLoginInfo> logins            = new List <UserLoginInfo>();
            string commandText                     = "SELECT * FROM " + fullTableName + " WHERE " + fielduserID.Quote() + " = @userId";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "@userId", userId }
            };

            var rows = _database.ExecuteQuery(commandText, parameters);

            foreach (var row in rows)
            {
                var login = new UserLoginInfo(row[fieldLoginProvider], row[fieldProviderKey], row[fieldProviderDisplayName]);
                logins.Add(login);
            }

            return(logins);
        }