Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Forked from cprieto/gist:478753
Created July 16, 2010 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfromaniello/478757 to your computer and use it in GitHub Desktop.
Save jfromaniello/478757 to your computer and use it in GitHub Desktop.
using System;
using BrokersWeb.Search.Domain;
using NHibernate;
using NHibernate.Criterion;
using System.Linq;
namespace BrokersWeb.Search.Data{
public class NhSearchListingQuery : ISearchListingQuery{
public NhSearchListingQuery(ISessionFactory factory){
ISession session = factory.GetCurrentSession();
}
public IQueryOver<Listing, Listing> Criteria { get; set; }
#region ISearchListingQuery Members
public string StateCode{ get; set; }
public int? ProductId{get; set;}
public int? AffiliateId{get; set;}
public int? ExcludedDomain{get;set;}
public int[] ClickedItems {get;set}
public int[] ExcludeCategories {get;set;}
public IPagedList<Listing> Query(int limit, int page){
var query = session.Query<Listing>();
if (!string.IsNullOrEmpty(value))
query = query.Where(l => l.StateCode == StateCode);
if(ProductId.HasValue)
query = query.Where(l => l.ProductId == ProductId.Value);
if(AffiliateId.HasValue)
query = query.Where(l => !l.Domain.Advertiser.ExcludedAffiliates.Any(a => a.Value == AffiliateId);
if(ExcludedDomain.HasValue)
query = query.Where(l => l.Domain.Id != ExcludedDomain.Value)
if(ExcludedCategories != null && ExcludedCategories.Any())
query = query.Where(l => !l.Domain.Advertiser.Categories.Any(c => c.Id == ExcludedCategories));
return ..........query)
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment