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

56 lines
1.9 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 : UnitOfWork<ProductGroup>
{
public new IList<ProductGroup> List()
{
return _session.QueryOver<ProductGroup>()
.OrderBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
}
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
{
return _session.QueryOver<ProductGroup>()
.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(Guid 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;
}
}
public void UpdateSortOrder(IList<ProductGroup> list)
{
int order = 0;
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
var productGroup = _session.Get<ProductGroup>(item.ProductGroupID);
productGroup.SortOrder = order;
_session.Update(productGroup);
}
}
}
}