narsil/Tanshu.Accounts.Repository/BusinessLayer/ProductGroupBI.cs

61 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Tanshu.Accounts.Entities;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class ProductGroupBI : FluentGenericBase<ProductGroup>
{
public ProductGroupBI()
: base()
{ }
public ProductGroupBI(bool beginTransaction)
: base(beginTransaction)
{ }
public ProductGroupBI(ISession session)
: base(session)
{ }
public ProductGroupBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public new IList<ProductGroup> List()
{
return Query()
.OrderBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
}
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
{
return Query()
.Where(query)
.OrderBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
}
public IList<string> GetProductGroupTypes()
{
const string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
var hnq = Session.CreateQuery(query);
return hnq.List<string>();
}
public ProductGroup GetProductGroupOfProduct(int productID)
{
using (var session = SessionManager.Session)
{
var item = (from p in session.QueryOver<Product>()
where p.ProductID == productID
select p.ProductGroup).SingleOrDefault<ProductGroup>();
NHibernateUtil.Initialize(item);
return item;
}
}
}
}