예제 #1
0
        /// <summary>Gets a collection of all the users in the SQL Server membership database.</summary>
        /// <returns>A <see cref="T:System.Web.Security.MembershipUserCollection"></see> of <see cref="T:System.Web.Security.MembershipUser"></see> objects representing all the users in the database for the configured <see cref="P:System.Web.Security.SqlMembershipProvider.ApplicationName"></see>.</returns>
        /// <param name="totalRecords">The total number of users.</param>
        /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param>
        /// <param name="pageSize">The size of the page of results to return.</param>
        /// <exception cref="T:System.ArgumentException">pageIndex is less than zero.- or -pageSize is less than one.- or -pageIndex multiplied by pageSize plus pageSize minus one exceeds <see cref="F:System.Int32.MaxValue"></see>.</exception>
        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            //
            // Calculate the first and last records
            //
            int firstUserIndex = pageIndex * pageSize;
            int lastUserIndex  = ((pageIndex * pageSize) + pageSize) - 1;

            if (pageIndex < 0)
            {
                throw new ArgumentException(Properties.Resources.PageIndex_bad, "pageIndex");
            }
            if (pageSize < 1)
            {
                throw new ArgumentException(Properties.Resources.PageSize_bad, "pageSize");
            }
            if (lastUserIndex > 0x7fffffff)
            {
                throw new ArgumentException(Properties.Resources.PageIndex_PageSize_bad, "pageIndex and pageSize");
            }


            //
            // Retrieve a users collection
            //
            System.Collections.Generic.IList <User> users = MembershipManager.GetAllUsers().ToList();
            totalRecords = users.Count;

            lastUserIndex = Math.Min(totalRecords, lastUserIndex);

            //
            // Enumerate the Membership.User and convert to MembershipUserCollection
            //
            MembershipUserCollection list = new MembershipUserCollection();

            for (int idx = firstUserIndex; idx < lastUserIndex; idx++)
            {
                list.Add(new VivinaMembershipUser(users[idx]));
            }

            return(list);
        }
예제 #2
0
 /// <summary>
 /// Get number of the users is online
 /// </summary>
 /// <returns></returns>
 public override int GetNumberOfUsersOnline()
 {
     return(MembershipManager.GetAllUsers().Where(usr => usr.IsOnline == true).Count());
 }