Пример #1
0
        private void ApplyCriterionForField(
            SortCriterionContext context, SortCriterionConfiguration criterion)
        {
            // This uses the logic from ContentFieldsSortCriterion
            var partDefinition = _contentDefinitionManager.GetPartDefinition(criterion.PartName);

            if (partDefinition == null)
            {
                Logger.Error(T("Impossible to find a part definition with name {0}.",
                               criterion.PartName).Text);
            }
            else
            {
                var fieldDefinition = partDefinition.Fields
                                      .FirstOrDefault(fd => fd.Name.Equals(criterion.FieldName));
                if (fieldDefinition == null)
                {
                    Logger.Error(T("Impossible to find a field definition with name {0} within the part {1}.",
                                   criterion.FieldName, criterion.PartName).Text);
                }
                else
                {
                    var propertyName = string.Join(".",
                                                   // part
                                                   criterion.PartName,
                                                   // field
                                                   criterion.FieldName,
                                                   // field's property (e.g. LinkField.Text)
                                                   criterion.PropertyName ?? "");

                    var fieldTypeEditors = GetFieldEditors(fieldDefinition.FieldDefinition.Name, criterion.PropertyName);
                    if (fieldTypeEditors.Any())
                    {
                        // I think there should be only one
                        foreach (var fieldTypeEditor in fieldTypeEditors)
                        {
                            // use an alias with the join so that two filters on the same Field Type wont collide
                            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());
                            // generate the predicate based on the editor which has been used
                            Action <IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);
                            // apply a filter for the specific property
                            context.Query = context.Query.Where(relationship, predicate);
                            // apply sort
                            context.Query = criterion.Ascending
                                ? context.Query.OrderBy(relationship, x => x.Asc(context.GetSortColumnName()))
                                : context.Query.OrderBy(relationship, x => x.Desc(context.GetSortColumnName()));
                        }
                    }
                    else
                    {
                        Logger.Error(T("Impossible to identify the IFieldTypeEditor to sort by {0}.", propertyName).Text);
                    }
                }
            }
        }
        public void ApplySortCriterion(SortCriterionContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            bool ascending    = (bool)context.State.Sort;
            var  propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action <IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService

            // apply where clause
            context.Query = context.Query.Where(relationship, predicate);

            // apply sort
            context.Query = ascending
                ? context.Query.OrderBy(relationship, x => x.Asc(context.GetSortColumnName()))
                : context.Query.OrderBy(relationship, x => x.Desc(context.GetSortColumnName()));
        }