Ejemplo n.º 1
0
        /// <summary>
        /// Returns an TUser given the user's id
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public TUser GetUserById(string userId)
        {
            TUser  user        = null;
            string commandText = "Select * from Users where Id = @id";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "@id", userId }
            };

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

            if (rows != null && rows.Count == 1)
            {
                var row = rows[0];
                user                      = (TUser)Activator.CreateInstance(typeof(TUser));
                user.Id                   = row["Id"];
                user.UserName             = row["UserName"];
                user.Status               = int.Parse(row["Status"]);
                user.PasswordHash         = string.IsNullOrEmpty(row["PasswordHash"]) ? null : row["PasswordHash"];
                user.SecurityStamp        = string.IsNullOrEmpty(row["SecurityStamp"]) ? null : row["SecurityStamp"];
                user.Email                = string.IsNullOrEmpty(row["Email"]) ? null : row["Email"];
                user.EmailConfirmed       = row["EmailConfirmed"] == "1" ? true:false;
                user.PhoneNumber          = string.IsNullOrEmpty(row["PhoneNumber"]) ? null : row["PhoneNumber"];
                user.Department           = string.IsNullOrEmpty(row["Department"]) ? null : row["Department"];
                user.DealerId             = string.IsNullOrEmpty(row["DealerId"]) ? null : row["DealerId"];
                user.DealerName           = string.IsNullOrEmpty(row["DealerName"]) ? null : row["DealerName"];
                user.PhoneNumberConfirmed = row["PhoneNumberConfirmed"] == "1" ? true : false;
                user.LockoutEnabled       = row["LockoutEnabled"] == "1" ? true : false;
                user.LockoutEndDateUtc    = string.IsNullOrEmpty(row["LockoutEndDateUtc"]) ? DateTime.Now : DateTime.Parse(row["LockoutEndDateUtc"]);
                user.AccessFailedCount    = string.IsNullOrEmpty(row["AccessFailedCount"]) ? 0 : int.Parse(row["AccessFailedCount"]);
            }

            return(user);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public List <IdentityRole> GetRoles(int pageIndex, int pageSize, out int totalCount)
        {
            string commandText = "SELECT COUNT(1) FROM roles where IsDelete=@isDel";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@isDel", 0);
            int.TryParse(_database.QueryValue(commandText, parameters).ToString(), out totalCount);

            List <IdentityRole> rolelList = new List <IdentityRole>();

            commandText = "select Id,Name,IsDelete,Describe from (select row_number() over (order by id) as row_num,* from roles) r where row_num between @pageIndex and @pageEnd";
            parameters.Add("@pageIndex", pageIndex);
            parameters.Add("@pageEnd", pageSize + pageIndex);
            var roles = _database.Query(commandText, parameters);

            foreach (var role in roles)
            {
                var identityRole = new IdentityRole();
                identityRole.Id       = role["Id"];
                identityRole.Name     = role["Name"];
                identityRole.Describe = role["Describe"];
                rolelList.Add(identityRole);
            }

            return(rolelList);
        }
Ejemplo n.º 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(string userId)
        {
            List <string> roles       = new List <string>();
            string        commandText = "Select Roles.Name from UserRoles, Roles where UserRoles.UserId = @userId and UserRoles.RoleId = Roles.Id and Roles.IsDelete = @isDel";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@userId", userId);
            parameters.Add("@isDel", 0);
            var rows = _database.Query(commandText, parameters);

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

            return(roles);
        }
Ejemplo n.º 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(string userId)
        {
            List <UserLoginInfo> logins            = new List <UserLoginInfo>();
            string commandText                     = "Select * from UserLogins 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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a ClaimsIdentity instance given a userId
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public ClaimsIdentity FindByUserId(string userId)
        {
            ClaimsIdentity claims                  = new ClaimsIdentity();
            string         commandText             = "Select * from UserClaims 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);
        }