Esempio n. 1
0
        public Task <FindResults <Project> > GetByFilterAsync(AppFilter systemFilter, string userFilter, string sort, CommandOptionsDescriptor <Project> options = null)
        {
            IRepositoryQuery <Project> query = new RepositoryQuery <Project>()
                                               .AppFilter(systemFilter)
                                               .FilterExpression(userFilter);

            query = !String.IsNullOrEmpty(sort) ? query.SortExpression(sort) : query.SortAscending(p => p.Name.Suffix("keyword"));
            return(FindAsync(q => query, options));
        }
Esempio n. 2
0
        public Task <FindResults <Organization> > GetByCriteriaAsync(string criteria, CommandOptionsDescriptor <Organization> options, OrganizationSortBy sortBy, bool?paid = null, bool?suspended = null)
        {
            var filter = Query <Organization> .MatchAll();

            if (!String.IsNullOrWhiteSpace(criteria))
            {
                filter &= Query <Organization> .Term(o => o.Name, criteria);
            }

            if (paid.HasValue)
            {
                if (paid.Value)
                {
                    filter &= !Query <Organization> .Term(o => o.PlanId, _plans.FreePlan.Id);
                }
                else
                {
                    filter &= Query <Organization> .Term(o => o.PlanId, _plans.FreePlan.Id);
                }
            }

            if (suspended.HasValue)
            {
                if (suspended.Value)
                {
                    filter &= (!Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Active) &&
                               !Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Trialing) &&
                               !Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Canceled)
                               ) || Query <Organization> .Term(o => o.IsSuspended, true);
                }
                else
                {
                    filter &= (
                        Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Active) &&
                        Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Trialing) &&
                        Query <Organization> .Term(o => o.BillingStatus, BillingStatus.Canceled)
                        ) || Query <Organization> .Term(o => o.IsSuspended, false);
                }
            }

            var query = new RepositoryQuery <Organization>().ElasticFilter(filter);

            switch (sortBy)
            {
            case OrganizationSortBy.Newest:
                query.SortDescending((Organization o) => o.Id);
                break;

            case OrganizationSortBy.Subscribed:
                query.SortDescending((Organization o) => o.SubscribeDate);
                break;

            // case OrganizationSortBy.MostActive:
            //    query.WithSortDescending((Organization o) => o.TotalEventCount);
            //    break;
            default:
                query.SortAscending(o => o.Name.Suffix("keyword"));
                break;
            }

            return(FindAsync(q => query, options));
        }