public Expression <Func <ProtoContent, bool> > HandleWhere(ContentWhereCondition condition, object param, ContentType contentType, out bool callNextHandler) { callNextHandler = true; if (!(param is BooleanFieldTableFilterFormItem)) { return(null); } var par = param.DirectCastTo <BooleanFieldTableFilterFormItem>(); if (!par.IsEnabled) { return(null); } var fn = $"{par.FieldName}.{nameof(BooleanField.Val)}"; var isCheck = par.IsChecked; // content field boolean value can be null, true, or false, so null is considered false if (isCheck) { return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.BooleanValue == true)); } return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.BooleanValue != true)); }
public Expression <Func <ProtoContent, bool> > HandleWhere(ContentWhereCondition condition, object param, ContentType contentType, out bool callNextHandler) { callNextHandler = true; if (!condition.IsTrashedCondition() && !(param is TrashingFieldTableFilterForm)) { return(null); } var par = param.DirectCastTo <TrashingFieldTableFilterForm>(); var tfn = $"{ContentType.FIELD_NAME_PUBLISH_STATUS}.{nameof(TrashingField.TrashedUtc)}"; var now = DateTime.UtcNow; if (par.IsTrashed) { return(x => ( from tf in x.ContentFields.Where(cf => cf.FieldName == tfn) select new { TrashedUtc = tf.DateTimeValue }).Any(y => y.TrashedUtc != null && y.TrashedUtc.Value <= now)); } return(x => !( from tf in x.ContentFields.Where(cf => cf.FieldName == tfn) select new { TrashedUtc = tf.DateTimeValue }).Any(y => y.TrashedUtc != null && y.TrashedUtc.Value <= now)); }
public Expression <Func <ProtoContent, bool> > HandleWhere(ContentWhereCondition condition, object param, ContentType contentType, out bool callNextHandler) { callNextHandler = true; var pf = new PublishingFieldTableFilterForm(); var tf = new TrashingFieldTableFilterForm(); var ok = false; if (condition.Is(StandardContentWhereConditionsProvider.IS_PUBLISHED_AND_NOT_TRASHED)) { pf.IsPublished = true; tf.IsTrashed = false; ok = true; } else if (condition.Is(StandardContentWhereConditionsProvider.IS_PUBLISHED_AND_TRASHED)) { pf.IsPublished = true; tf.IsTrashed = true; ok = true; } else if (condition.Is(StandardContentWhereConditionsProvider.IS_NOT_PUBLISHED_AND_NOT_TRASHED)) { pf.IsPublished = false; tf.IsTrashed = false; ok = true; } else if (condition.Is(StandardContentWhereConditionsProvider.IS_NOT_PUBLISHED_AND_TRASHED)) { pf.IsPublished = false; tf.IsTrashed = true; ok = true; } if (!ok) { return(null); } var pred = PredicateBuilder.True <ProtoContent>(); var pubCond = ContentFinder.DefinedWhereConditions.First(x => x.Is(PublishingFieldWhereConditionsProvider.IS_PUBLISHED_WHERE_CONDITION_NAME)); var pubPred = _pubHdlr.HandleWhere(pubCond, pf, contentType, out var pubCnh); var traCond = ContentFinder.DefinedWhereConditions.First(x => x.Is(TrashingFieldWhereConditionsProvider.IS_TRASHED_WHERE_CONDITION_NAME)); var traPred = _traHdlr.HandleWhere(traCond, tf, contentType, out var traCnh); pred = pred.And(pubPred); pred = pred.And(traPred); return(pred); }
public Expression <Func <ProtoContent, bool> > HandleWhere(ContentWhereCondition condition, object param, ContentType contentType, out bool callNextHandler) { callNextHandler = true; if (!(param is ChronoFieldTableFilterFormItem)) { return(null); } var par = param.DirectCastTo <ChronoFieldTableFilterFormItem>(); if (!par.IsEnabled) { return(null); } var fn = $"{par.FieldName}.{nameof(ChronoField.Val)}"; if (par.IsNullValue) { return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.DateTimeValue == null)); } var min = par.MinDateTime ?? DateTime.Now; var max = par.MaxDateTime ?? DateTime.Now; if (par.GreaterThanOrEqualToMin) { if (par.LessThanOrEqualToMax) { return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.DateTimeValue >= min && cf.DateTimeValue <= max)); } return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.DateTimeValue >= min && cf.DateTimeValue < max)); } if (par.LessThanOrEqualToMax) { return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.DateTimeValue > min && cf.DateTimeValue <= max)); } return(x => x.ContentFields.Any(cf => cf.FieldName == fn && cf.DateTimeValue > min && cf.DateTimeValue < max)); }