Ejemplo n.º 1
0
        /// <summary>
        /// Returns the role Id given a role name
        /// </summary>
        /// <param name="roleName">Role's name</param>
        /// <returns>Role's Id</returns>
        public string GetRoleId(string roleName)
        {
            ConnectionService.ThreadVanityUrl = ConnectionName;

            string roleId = null;

            AspNetRolesQuery q = new AspNetRolesQuery();

            q.Select(q.Id);
            q.Where(q.Name == roleName);

            AspNetRoles role = new AspNetRoles();

            SetConnection(role);
            if (role.Load(q))
            {
                roleId = role.Id;
            }

            return(roleId);
        }
Ejemplo n.º 2
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)
        {
            ConnectionService.ThreadVanityUrl = ConnectionName;

            List <string> roles = new List <string>();

            AspNetRolesQuery     r  = new AspNetRolesQuery("r");
            AspNetUserRolesQuery ur = new AspNetUserRolesQuery("ur");

            r.Select(r.Name);
            r.InnerJoin(ur).On(ur.UserId == userId && ur.RoleId == r.Id);

            AspNetRolesCollection coll = new AspNetRolesCollection();

            if (coll.Load(r))
            {
                foreach (AspNetRoles role in coll)
                {
                    roles.Add(role.Name);
                }
            }

            return(roles);
        }