2011-06-29 20:27:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq.Expressions;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-01-31 20:33:22 +00:00
|
|
|
|
using NHibernate;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public class ProductGroupBI : UnitOfWork<ProductGroup>
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public new IList<ProductGroup> List()
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
return _session.QueryOver<ProductGroup>()
|
2011-06-29 20:27:07 +00:00
|
|
|
|
.OrderBy(x => x.SortOrder).Asc
|
|
|
|
|
.ThenBy(x => x.Name).Asc
|
|
|
|
|
.List();
|
|
|
|
|
}
|
|
|
|
|
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
|
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
return _session.QueryOver<ProductGroup>()
|
2011-06-29 20:27:07 +00:00
|
|
|
|
.Where(query)
|
|
|
|
|
.OrderBy(x => x.SortOrder).Asc
|
|
|
|
|
.ThenBy(x => x.Name).Asc
|
2011-06-23 12:47:48 +00:00
|
|
|
|
.List();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public IList<string> GetProductGroupTypes()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
const string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
|
2014-10-12 09:41:45 +00:00
|
|
|
|
var hnq = _session.CreateQuery(query);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return hnq.List<string>();
|
2011-02-18 16:54:48 +00:00
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public ProductGroup GetProductGroupOfProduct(Guid productID)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
var item = (from p in session.QueryOver<Product>()
|
2011-06-23 12:47:48 +00:00
|
|
|
|
where p.ProductID == productID
|
|
|
|
|
select p.ProductGroup).SingleOrDefault<ProductGroup>();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
NHibernateUtil.Initialize(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|