Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Apply method returns a function which operates on a IQueryable<T> to filter its results.  You can assume that all the items in the IQueryable are already assignable to ApplicableType.  Notice the use of AsFacade so you can work with the IQueryable as if it was an IPublishable.

Code Block
/// <summary>
/// ListFilter for filtering by properties to do with Publishing
/// </summary>
public class PublishingFilter : ListFilter
{
  /// <summary>
  /// Show items which have never been published
  /// </summary>
  public bool NeverPublished { get; set; }

...


  /// <summary>
  /// Show items which have been updated since they were last published
  /// </summary>
  public bool RequiringPublishing { get; set; }
 
  public PublishingFilter()
  {
    ApplicableType = typeof(IPublishable);
  }
 
  public override string Name

...

 {

...

 

...

get 

...

{

...

 

...

return "Publishing"; 

...

}

...

 set

...

 

...

{

...

 

...

base.Name = value; 

...

}

...

 

...

}
 
  public override void MergeOriginal(ListFilter filt)
  { }
 
  public override bool Active
  {
    get { return NeverPublished || RequiringPublishing; }
  }
 
  public override string GetShowText(Tuple<object, Lynicon.Models.Summary> row)
  {
    if (row.Item1 is IPublishable)
    {
      var iPub = row.Item1 as IPublishable;
      if (iPub.Published < iPub.Updated - TimeSpan.FromMilliseconds(750))
        return "Needs Pub";
    }
    return "";
  }
  
  public override Func<IQueryable<T>, IQueryable<T>> Apply<T>()
  {
    if (NeverPublished)
      return iq => iq.AsFacade<IPublishable>()
        .Where(ipub => ipub.Published == null)
        .AsFacade<T>();
    else
      return iq => iq
        .AsFacade<IPublishable>()
        .Where(ipub => ipub.Published == null || ipub.Published < ipub.Updated)
        .AsFacade<T>();
  }
}