private static IWhereExpression GetExpression(IWhereExpression inner, WhereClause clause, Schema schema, IValueProvider valueProvider) { var binder = EngineContext.Current.Resolve <ITextContentBinder>(); var value = ParameterizedFieldValue.GetFieldValue(clause.Value1, valueProvider); var fieldValue = binder.ConvertToColumnType(schema, clause.FieldName, value); if (clause.Logical == Logical.Or && string.IsNullOrEmpty(value)) { return(null); } switch (clause.Operator) { case Operator.Equals: return(new WhereEqualsExpression(inner, clause.FieldName, fieldValue)); case Operator.NotEquals: return(new WhereNotEqualsExpression(inner, clause.FieldName, fieldValue)); case Operator.GreaterThan: return(new WhereGreaterThanExpression(inner, clause.FieldName, fieldValue)); case Operator.LessThan: return(new WhereLessThanExpression(inner, clause.FieldName, fieldValue)); case Operator.Contains: return(new WhereContainsExpression(inner, clause.FieldName, fieldValue)); case Operator.StartsWith: return(new WhereStartsWithExpression(inner, clause.FieldName, fieldValue)); case Operator.EndsWith: return(new WhereEndsWithExpression(inner, clause.FieldName, fieldValue)); case Operator.Between: var value2 = ParameterizedFieldValue.GetFieldValue(clause.Value2, valueProvider); var fieldValue2 = binder.ConvertToColumnType(schema, clause.Value2, value2); return(new WhereBetweenExpression(inner, clause.FieldName, fieldValue, fieldValue2)); case Operator.NotNull: return(new AndAlsoExpression(new WhereNotEqualsExpression(inner, clause.FieldName, null), new WhereNotEqualsExpression(inner, clause.FieldName, ""))); case Operator.IsNull: return(new OrElseExpression(new WhereEqualsExpression(inner, clause.FieldName, null), new WhereEqualsExpression(inner, clause.FieldName, ""))); default: return(null); } }
private static IWhereExpression GetExpression(IWhereExpression inner, WhereClause clause, Schema schema, IValueProvider valueProvider) { var value = ParameterizedFieldValue.GetFieldValue(clause.Value1, valueProvider); var fieldValue = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.ConvertToColumnType(schema, clause.FieldName, value); if (clause.Logical == Logical.Or && string.IsNullOrEmpty(value)) { return(null); } switch (clause.Operator) { case Operator.Equals: return(new WhereEqualsExpression(inner, clause.FieldName, fieldValue)); case Operator.NotEquals: return(new WhereNotEqualsExpression(inner, clause.FieldName, fieldValue)); case Operator.GreaterThan: return(new WhereGreaterThanExpression(inner, clause.FieldName, fieldValue)); case Operator.LessThan: return(new WhereLessThanExpression(inner, clause.FieldName, fieldValue)); case Operator.Contains: return(new WhereContainsExpression(inner, clause.FieldName, fieldValue)); case Operator.StartsWith: return(new WhereStartsWithExpression(inner, clause.FieldName, fieldValue)); case Operator.EndsWith: return(new WhereEndsWithExpression(inner, clause.FieldName, fieldValue)); case Operator.Between: var value2 = ParameterizedFieldValue.GetFieldValue(clause.Value2, valueProvider); var fieldValue2 = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.ConvertToColumnType(schema, clause.Value2, value2); return(new WhereBetweenExpression(inner, clause.FieldName, fieldValue, fieldValue2)); default: return(null); } }
public static void Execute(ViewDataDictionary viewData, DataRuleContext dataRuleContext, IEnumerable <DataRuleSetting> dataRules) { foreach (var item in dataRules) { var contentQuery = item.DataRule.Execute(dataRuleContext); object data = contentQuery; if (item.DataRule is DataRuleBase) { var dataRuleBase = (DataRuleBase)item.DataRule; if (!string.IsNullOrEmpty(dataRuleBase.SortField)) { if (dataRuleBase.SortDirection == DataRule.SortDirection.Ascending) { contentQuery = contentQuery.OrderBy(dataRuleBase.SortField); } else { contentQuery = contentQuery.OrderByDescending(dataRuleBase.SortField); } } if (item.DataRule.EnablePaging()) { string pageIndexParameterName; var pageIndexValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName); var intPageIndexValue = 1; int.TryParse(pageIndexValue, out intPageIndexValue); if (intPageIndexValue < 1) { intPageIndexValue = 1; } string pageSizeParameterName; var pageSizeValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName); var intPageSize = 10; int.TryParse(pageSizeValue, out intPageSize); if (intPageSize < 1) { intPageSize = 10; } var totalCount = contentQuery.Count(); data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize) , intPageIndexValue , intPageSize , totalCount) { PageIndexParameterName = pageIndexParameterName }; } else if (!string.IsNullOrEmpty(dataRuleBase.Top)) { string fieldName; var topValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.Top, dataRuleContext.ValueProvider, out fieldName); var intTopValue = 1; int.TryParse(topValue, out intTopValue); data = contentQuery.Take(intTopValue); } } if (data is IContentQuery <ContentBase> ) { data = GetData(item, (IContentQuery <TextContent>)data); } if (item.DataName.EqualsOrNullEmpty(ModelName, StringComparison.CurrentCultureIgnoreCase)) { viewData.Model = data; } viewData[item.DataName] = data; } }
public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration) { var contentQuery = this.GetContentQuery(dataRuleContext); object data = contentQuery; if (!string.IsNullOrEmpty(this.SortField)) { if (this.SortDirection == DataRule.SortDirection.Ascending) { contentQuery = contentQuery.OrderBy(this.SortField); } else { contentQuery = contentQuery.OrderByDescending(this.SortField); } } if (this.EnablePaging.Value) { string pageIndexParameterName; var pageIndexValue = ParameterizedFieldValue.GetFieldValue(this.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName); var intPageIndexValue = 1; int.TryParse(pageIndexValue, out intPageIndexValue); if (intPageIndexValue < 1) { intPageIndexValue = 1; } string pageSizeParameterName; var pageSizeValue = ParameterizedFieldValue.GetFieldValue(this.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName); var intPageSize = 10; int.TryParse(pageSizeValue, out intPageSize); if (intPageSize < 1) { intPageSize = 10; } var totalCount = contentQuery.Count(); data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize) , intPageIndexValue , intPageSize , totalCount) { PageIndexParameterName = pageIndexParameterName }; } else if (!string.IsNullOrEmpty(this.Top)) { string fieldName; var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName); var intTopValue = 1; int.TryParse(topValue, out intTopValue); data = contentQuery.Take(intTopValue); } else { data = contentQuery; } if (data is IContentQuery <ContentBase> ) { data = GetData((IContentQuery <TextContent>)data, operation, cacheDuration); } return(data); }