コード例 #1
0
        public IDocumentQuery <Package> CreateCurrentInventoryQuery(IDocumentSession session,
                                                                    string communityCode,
                                                                    string sortBy,
                                                                    bool sortDescending,
                                                                    bool viewIsDeleted,
                                                                    DefconFilter defconFilter,
                                                                    string unitResidentFilter,
                                                                    int?take)
        {
            IDocumentQuery <Package> query = session.Advanced.LuceneQuery <Package>("Package/CurrentInventory").Take(take.Value);

            query.WhereEquals("CommunityCode", communityCode);
            query.AndAlso().Not.WhereEquals("Status", PackageStatusCodes.Released);

            if (!viewIsDeleted)
            {
                query.AndAlso();
                query.WhereEquals("IsDeleted", false);
            }

            DefConFilterQuery(query, defconFilter);

            if (!string.IsNullOrEmpty(unitResidentFilter))
            {
                query.AndAlso();
                query.WhereEquals("AddressName", unitResidentFilter);
            }

            if (!string.IsNullOrEmpty((sortBy)))
            {
                query.AddOrder(sortBy, sortDescending);
            }
            return(query);
        }
コード例 #2
0
        public static IDocumentQuery <T> ConditionalSort <T>(this IDocumentQuery <T> query, string fieldName, bool descending, bool condition)
        {
            if (condition)
            {
                return(query.AddOrder(fieldName, descending));
            }

            return(query);
        }
コード例 #3
0
        public static IDocumentQuery <TSource> Sort <TSource>(this IDocumentQuery <TSource> source, Request request)
        {
            var direction  = "desc";
            var descending = true;

            if (request.Query.direction.HasValue)
            {
                direction = (string)request.Query.direction;
            }

            if (direction == "asc")
            {
                descending = false;
            }

            var sortOptions = new[]
            {
                "id", "message_id", "message_type",
                "time_sent", "status"
            };

            var    sort = "time_sent";
            string keySelector;

            if (request.Query.sort.HasValue)
            {
                sort = (string)request.Query.sort;
            }

            if (!sortOptions.Contains(sort))
            {
                sort = "time_sent";
            }

            switch (sort)
            {
            case "id":
            case "message_id":
                keySelector = "MessageId";
                break;

            case "message_type":
                keySelector = "MessageType";
                break;

            case "status":
                keySelector = "Status";
                break;

            default:
                keySelector = "TimeSent";
                break;
            }

            return(source.AddOrder(keySelector, descending));
        }
コード例 #4
0
        private void VisitOrderBy(LambdaExpression expression, bool descending)
        {
            var member       = ((MemberExpression)expression.Body).Member;
            var propertyInfo = ((MemberExpression)expression.Body).Member as PropertyInfo;
            var fieldInfo    = ((MemberExpression)expression.Body).Member as FieldInfo;
            var name         = member.Name;
            var type         = propertyInfo != null
                                        ? propertyInfo.PropertyType
                                        : (fieldInfo != null ? fieldInfo.FieldType : typeof(object));

            luceneQuery.AddOrder(name, descending, type);
        }
コード例 #5
0
        private void VisitOrderBy(LambdaExpression expression, bool descending)
        {
            var name = ((MemberExpression)expression.Body).Member.Name;

            luceneQuery.AddOrder(name, descending);
        }