static public List <MembershipUserWrapper> GetMembers(bool returnAllApprovedUsers, bool returnAllNotApprovedUsers,
                                                              string usernameToFind, string sortData)
        {
            List <MembershipUserWrapper> memberList = new List <MembershipUserWrapper>();

            // See if we are looking for just one user
            if (usernameToFind != null)
            {
                MembershipUser mu = Membership.GetUser(usernameToFind);
                if (mu != null)
                {
                    MembershipUserWrapper md = new MembershipUserWrapper(mu);
                    memberList.Add(md);
                }
            }
            else
            {
                MembershipUserCollection muc = Membership.GetAllUsers();
                foreach (MembershipUser mu in muc)
                {
                    if ((returnAllApprovedUsers == true && mu.IsApproved == true) ||
                        (returnAllNotApprovedUsers == true && mu.IsApproved == false))
                    {
                        MembershipUserWrapper md = new MembershipUserWrapper(mu);
                        memberList.Add(md);
                    }
                }

                if (sortData == null)
                {
                    sortData = "UserName";
                }
                if (sortData.Length == 0)
                {
                    sortData = "UserName";
                }

                // Make a special version of sortData for the switch statement so that whether or not the
                // DESC is appended to the string sortData, it will switch on the base of that string.
                string sortDataBase = sortData; // init and assume there is not DESC appended to sortData
                string descString   = " DESC";
                if (sortData.EndsWith(descString))
                {
                    sortDataBase = sortData.Substring(0, sortData.Length - descString.Length);
                }

                Comparison <MembershipUserWrapper> comparison = null;

                switch (sortDataBase)
                {
                case "UserName":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.UserName.CompareTo(rhs.UserName));
                    }
                        );
                    break;

                case "Email":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        if (lhs.Email == null | rhs.Email == null)
                        {
                            return(0);
                        }
                        else
                        {
                            return(lhs.Email.CompareTo(rhs.Email));
                        }
                    }
                        );
                    break;

                case "CreationDate":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.CreationDate.CompareTo(rhs.CreationDate));
                    }
                        );
                    break;

                case "IsApproved":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.IsApproved.CompareTo(rhs.IsApproved));
                    }
                        );
                    break;

                case "IsOnline":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.IsOnline.CompareTo(rhs.IsOnline));
                    }
                        );
                    break;

                case "LastLoginDate":
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.LastLoginDate.CompareTo(rhs.LastLoginDate));
                    }
                        );
                    break;

                default:
                    comparison = new Comparison <MembershipUserWrapper>(
                        delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                    {
                        return(lhs.UserName.CompareTo(rhs.UserName));
                    }
                        );
                    break;
                }

                if (sortData.EndsWith("DESC"))
                {
                    memberList.Sort(comparison);
                    memberList.Reverse();
                }
                else
                {
                    memberList.Sort(comparison);
                }
            }

            // FxCopy will give us a warning about returning a List rather than a Collection.
            // We could copy the data, but not worth the trouble.
            return(memberList);
        }
        public static List<MembershipUserWrapper> GetMembers(bool returnAllApprovedUsers, bool returnAllNotApprovedUsers,
            string usernameToFind, string sortData)
        {
            List<MembershipUserWrapper> memberList = new List<MembershipUserWrapper>();

            // See if we are looking for just one user
            if (usernameToFind != null)
            {
                MembershipUser mu = Membership.GetUser(usernameToFind);
                if (mu != null)
                {
                    MembershipUserWrapper md = new MembershipUserWrapper(mu);
                    memberList.Add(md);
                }
            }
            else
            {
                MembershipUserCollection muc = Membership.GetAllUsers();
                foreach (MembershipUser mu in muc)
                {
                    if ((returnAllApprovedUsers == true && mu.IsApproved == true) ||
                         (returnAllNotApprovedUsers == true && mu.IsApproved == false))
                    {
                        MembershipUserWrapper md = new MembershipUserWrapper(mu);
                        memberList.Add(md);
                    }
                }

                if (sortData == null)
                {
                    sortData = "UserName";
                }
                if (sortData.Length == 0)
                {
                    sortData = "UserName";
                }

                // Make a special version of sortData for the switch statement so that whether or not the
                // DESC is appended to the string sortData, it will switch on the base of that string.
                string sortDataBase = sortData; // init and assume there is not DESC appended to sortData
                string descString = " DESC";
                if (sortData.EndsWith(descString))
                {
                    sortDataBase = sortData.Substring(0, sortData.Length - descString.Length);
                }

                Comparison<MembershipUserWrapper> comparison = null;

                switch (sortDataBase)
                {
                    case "UserName":
                        comparison = new Comparison<MembershipUserWrapper>(
                            delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                            {
                                return lhs.UserName.CompareTo(rhs.UserName);
                            }
                            );
                        break;
                    case "Email":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 if (lhs.Email == null | rhs.Email == null)
                                 {
                                     return 0;
                                 }
                                 else
                                 {
                                     return lhs.Email.CompareTo(rhs.Email);
                                 }
                             }
                             );
                        break;
                    case "CreationDate":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.CreationDate.CompareTo(rhs.CreationDate);
                             }
                             );
                        break;
                    case "IsApproved":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.IsApproved.CompareTo(rhs.IsApproved);
                             }
                             );
                        break;
                    case "IsOnline":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.IsOnline.CompareTo(rhs.IsOnline);
                             }
                             );
                        break;
                    case "LastLoginDate":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);
                             }
                             );
                        break;
                    default:
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.UserName.CompareTo(rhs.UserName);
                             }
                             );
                        break;
                }

                if (sortData.EndsWith("DESC"))
                {
                    memberList.Sort(comparison);
                    memberList.Reverse();
                }
                else
                {
                    memberList.Sort(comparison);
                }

            }

            // FxCopy will give us a warning about returning a List rather than a Collection.
            // We could copy the data, but not worth the trouble.
            return memberList;
        }
Ejemplo n.º 3
0
        public static List<MembershipUserWrapper> GetMembers(bool returnAllApprovedUsers, bool returnAllNotApprovedUsers,
            string usernameToFind, string sortData, int maximumRows, int startRowIndex)
        {
            List<MembershipUserWrapper> memberList = new List<MembershipUserWrapper>();

            // See if we are looking for just one user
            if (usernameToFind != null)
            {
                MembershipUser mu = Membership.GetUser(usernameToFind);
                if (mu != null)
                {
                    MembershipUserWrapper md = new MembershipUserWrapper(mu);
                    memberList.Add(md);
                }
            }
            else
            {
                MembershipUserCollection muc = null;
                if (startRowIndex == -1)
                {
                    muc = Membership.GetAllUsers();
                }
                else
                {
                    // We are given: startRowIndex and maximumRows to display
                    // We need to convert that to pageIndex,pageSize,totalRecords
                    //
                    // Assume, maximumRows is pageSize
                    // Need to figure out how many pageSizes before startRowIndex
                    // so
                    //
                    int pageStart = startRowIndex / maximumRows;

                    // this is bad because it probably forces a retrieve of all records
                    // (what we are trying to avoid)
                    //int totalRecords = Membership.GetAllUsers().Count;
                    int totalRecords;
                    muc = Membership.GetAllUsers(pageStart, 5, out totalRecords);
                }
                foreach (MembershipUser mu in muc)
                {
                    if ((returnAllApprovedUsers == true && mu.IsApproved == true) ||
                         (returnAllNotApprovedUsers == true && mu.IsApproved == false))
                    {
                        MembershipUserWrapper md = new MembershipUserWrapper(mu);
                        memberList.Add(md);
                    }
                }

                if (sortData == null)
                {
                    sortData = "UserName";
                }
                if (sortData.Length == 0)
                {
                    sortData = "UserName";
                }

                // Make a special version of sortData for the switch statement so that whether or not the
                // DESC is appended to the string sortData, it will switch on the base of that string.
                string sortDataBase = sortData; // init and assume there is not DESC appended to sortData
                string descString = " DESC";
                if (sortData.EndsWith(descString))
                {
                    sortDataBase = sortData.Substring(0, sortData.Length - descString.Length);
                }

                Comparison<MembershipUserWrapper> comparison = null;

                switch (sortDataBase)
                {
                    case "UserName":
                        comparison = new Comparison<MembershipUserWrapper>(
                            delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                            {
                                return lhs.UserName.CompareTo(rhs.UserName);
                            }
                            );
                        break;
                    case "Email":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 if (lhs.Email == null | rhs.Email == null)
                                 {
                                     return 0;
                                 }
                                 else
                                 {
                                     return lhs.Email.CompareTo(rhs.Email);
                                 }
                             }
                             );
                        break;
                    case "Comment":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 if (lhs.Comment == null | rhs.Comment == null)
                                 {
                                     return 0;
                                 }
                                 else
                                 {
                                     return lhs.Comment.CompareTo(rhs.Comment);
                                 }
                             }
                             );
                        break;
                    case "CreationDate":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.CreationDate.CompareTo(rhs.CreationDate);
                             }
                             );
                        break;
                    case "IsApproved":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.IsApproved.CompareTo(rhs.IsApproved);
                             }
                             );
                        break;
                    case "IsOnline":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.IsOnline.CompareTo(rhs.IsOnline);
                             }
                             );
                        break;
                    case "LastLoginDate":
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);
                             }
                             );
                        break;
                    default:
                        comparison = new Comparison<MembershipUserWrapper>(
                             delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)
                             {
                                 return lhs.UserName.CompareTo(rhs.UserName);
                             }
                             );
                        break;
                }

                if (sortData.EndsWith("DESC"))
                {
                    memberList.Sort(comparison);
                    memberList.Reverse();
                }
                else
                {
                    memberList.Sort(comparison);
                }

            }

            // FxCopy will give us a warning about returning a List rather than a Collection.
            // We could copy the data, but not worth the trouble.
            return memberList;
        }