コード例 #1
0
        /// <summary>
        /// Returns all users.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <TUser> GetAllUsers()
        {
            var          users       = new List <TUser>();
            const string commandText = "SELECT * FROM \"AspNetUsers\"";
            var          rows        = _database.Query(commandText, new Dictionary <String, Object>());

            foreach (var row in rows)
            {
                var user = new TUser {
                    Id             = Guid.Parse(row["Id"]),
                    UserName       = row["UserName"],
                    PasswordHash   = String.IsNullOrEmpty(row["PasswordHash"]) ? null : row["PasswordHash"],
                    SecurityStamp  = String.IsNullOrEmpty(row["SecurityStamp"]) ? null : row["SecurityStamp"],
                    Email          = String.IsNullOrEmpty(row["Email"]) ? null : row["Email"],
                    EmailConfirmed = row["EmailConfirmed"] == "True"
                };
                users.Add(user);
            }

            return(users);
        }
コード例 #2
0
        /// <summary>
        /// Returns all role names.
        ///
        /// Created by: Slawomir Figiel
        /// </summary>
        /// <returns>Role name.</returns>
        public List <IdentityRole> GetAllRoleNames()
        {
            List <IdentityRole> roles = new List <IdentityRole>();
            String commandText        = "SELECT * FROM \"AspNetRoles\"";
            var    rows = _database.Query(commandText, new Dictionary <String, Object>());

            foreach (var row in rows)
            {
                IdentityRole r = new IdentityRole(row["Name"], row["Id"]);
                roles.Add(r);
            }
            return(roles);
        }
コード例 #3
0
        /// <summary>
        /// Returns a list of user's roles.
        /// </summary>
        /// <param name="userId">The user's id.</param>
        /// <returns></returns>
        public List <String> FindByUserId(Guid userId)
        {
            List <String> roles = new List <String>();

            var commandText = "SELECT \"AspNetRoles\".\"Name\" FROM \"AspNetRoles\" JOIN \"AspNetUserRoles\" ON \"AspNetUserRoles\".\"RoleId\" = \"AspNetRoles\".\"Id\" WHERE \"AspNetUserRoles\".\"UserId\" = @userId;";
            var parameters  = new Dictionary <String, Object>();

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

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

            foreach (var row in rows)
            {
                roles.Add(row["Name"]);
            }

            return(roles);
        }
コード例 #4
0
        /// <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 \"AspNetUserLogins\" WHERE \"UserId\" = @userId";
            Dictionary <String, Object> parameters = new Dictionary <String, Object>()
            {
                { "@userId", userId }
            };

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

            foreach (var row in rows)
            {
                var login = new UserLoginInfo(row["LoginProvider"], row["ProviderKey"]);
                logins.Add(login);
            }

            return(logins);
        }
コード例 #5
0
        /// <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 \"AspNetUserClaims\" WHERE \"UserId\" = @userId";
            Dictionary <String, Object> parameters = new Dictionary <String, Object>()
            {
                { "@UserId", userId }
            };

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

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

            return(claims);
        }