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;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
using NHibernate.Criterion;
|
|
|
|
|
using NHibernate.Transform;
|
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-11-02 08:03:31 +00:00
|
|
|
|
_session.FlushMode = FlushMode.Never;
|
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
|
|
|
|
}
|
2014-11-02 08:03:31 +00:00
|
|
|
|
public IList<ProductGroup> SaleList()
|
|
|
|
|
{
|
|
|
|
|
ProductGroup pgAlias = null;
|
|
|
|
|
Product pAlias = null;
|
|
|
|
|
ICriterion isActive = Restrictions.Where<Product>(x => x.IsActive);
|
|
|
|
|
|
|
|
|
|
return _session.QueryOver<ProductGroup>(() => pgAlias)
|
|
|
|
|
.Left.JoinAlias(x => x.Products, () => pAlias, isActive)
|
|
|
|
|
.Where(x => x.IsActive)
|
|
|
|
|
.OrderBy(x => x.SortOrder).Asc
|
|
|
|
|
.ThenBy(x => x.Name).Asc
|
|
|
|
|
.ThenBy(() => pAlias.SortOrder).Asc
|
|
|
|
|
.ThenBy(() => pAlias.Name).Asc
|
|
|
|
|
.TransformUsing(Transformers.DistinctRootEntity)
|
|
|
|
|
.List();
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = list[i];
|
|
|
|
|
var productGroup = _session.Get<ProductGroup>(item.ProductGroupID);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
productGroup.SortOrder = i;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
_session.Update(productGroup);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|