Example #1
0
    /// <summary>
    ///     Gets the total number of Users based on the count type
    /// </summary>
    /// <remarks>
    ///     The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any
    ///     members
    ///     that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact
    ///     science
    ///     but that is how MS have made theirs so we'll follow that principal.
    /// </remarks>
    /// <param name="countType"><see cref="MemberCountType" /> to count by</param>
    /// <returns><see cref="System.int" /> with number of Users for passed in type</returns>
    public int GetCount(MemberCountType countType)
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
        {
            IQuery <IUser>?query;

            switch (countType)
            {
            case MemberCountType.All:
                query = Query <IUser>();
                break;

            case MemberCountType.LockedOut:
                query = Query <IUser>()?.Where(x => x.IsLockedOut);
                break;

            case MemberCountType.Approved:
                query = Query <IUser>()?.Where(x => x.IsApproved);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(countType));
            }

            return(_userRepository.GetCountByQuery(query));
        }
    }
        /// <summary>
        /// Gets the total number of Users based on the count type
        /// </summary>
        /// <remarks>
        /// The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members
        /// that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science
        /// but that is how MS have made theirs so we'll follow that principal.
        /// </remarks>
        /// <param name="countType"><see cref="MemberCountType"/> to count by</param>
        /// <returns><see cref="System.int"/> with number of Users for passed in type</returns>
        public int GetCount(MemberCountType countType)
        {
            using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
            {
                var repository = RepositoryFactory.CreateUserRepository(uow);

                IQuery <IUser> query;
                int            ret;
                switch (countType)
                {
                case MemberCountType.All:
                    query = new Query <IUser>();
                    ret   = repository.Count(query);
                    break;

                case MemberCountType.Online:
                    throw new NotImplementedException();

                //var fromDate = DateTime.Now.AddMinutes(-Membership.UserIsOnlineTimeWindow);
                //query =
                //    Query<IMember>.Builder.Where(
                //        x =>
                //        ((Member)x).PropertyTypeAlias == Constants.Conventions.Member.LastLoginDate &&
                //        ((Member)x).DateTimePropertyValue > fromDate);
                //return repository.GetCountByQuery(query);
                case MemberCountType.LockedOut:
                    query = Query <IUser> .Builder.Where(x => x.IsLockedOut);

                    ret = repository.GetCountByQuery(query);
                    break;

                case MemberCountType.Approved:
                    query = Query <IUser> .Builder.Where(x => x.IsApproved);

                    ret = repository.GetCountByQuery(query);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("countType");
                }

                return(ret);
            }
        }