コード例 #1
0
        /// <summary>
        /// Get all the users from the database who are not admin users
        /// </summary>
        /// <returns>A list with all the not-admin users</returns>
        /// See <see cref="Areas.Admin.Models.UserSearchInfo"/> to know the response structure
        public List <UserSearchInfo> getAllUsers()
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context);

            if (!AdminPolicy.isAdmin(user, _context))
            {
                return(new List <UserSearchInfo>());
            }
            List <UserSearchInfo> userRet = new List <UserSearchInfo>();
            Role adminRole = RoleManager.getAdmin(_context);

            return(MakeListUserSearchInfo.make(_context.User.Where(u => u.role != adminRole).Take(25).ToList(), _context));
        }
コード例 #2
0
        /// <summary>
        /// Search a specific user
        /// </summary>
        /// <param name="toFind">The username or email of the user to find</param>
        /// <returns>A list with all the not-admin users who username or email match with the param</returns>
        /// See <see cref="Areas.Admin.Models.UserSearchInfo"/> to know the response structure
        public List <UserSearchInfo> searchUser(string toFind)
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context);

            if (!AdminPolicy.isAdmin(user, _context))
            {
                return(new List <UserSearchInfo>());
            }

            //The request name is empty
            if (toFind == null || toFind.Length == 0)
            {
                return(new List <UserSearchInfo>());
            }

            Role        adminRole        = RoleManager.getAdmin(_context);
            List <User> userWithSameMail = _context.User.Where(u =>
                                                               (u.email.ToLower().Contains(toFind.ToLower().Trim()) ||
                                                                u.nickname.ToLower().Contains(toFind.ToLower().Trim())) &&
                                                               u.role != adminRole
                                                               ).ToList();

            return(MakeListUserSearchInfo.make(userWithSameMail, _context));
        }