2011-01-30 07:14:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using System.Linq.Expressions;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-06-23 12:47:48 +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 ProductBI : UnitOfWork<Product>
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public Product Get(string nameAndUnits)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return Get(x => x.Name + " (" + x.Units + ")" == nameAndUnits);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public new IList<Product> List(Expression<Func<Product, bool>> query)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
var list = _session.QueryOver<Product>()
|
2011-06-29 20:27:07 +00:00
|
|
|
|
.Where(query)
|
2014-11-20 08:12:20 +00:00
|
|
|
|
.OrderBy(x => x.ProductGroup).Asc
|
2011-06-29 20:27:07 +00:00
|
|
|
|
.OrderBy(x => x.SortOrder).Asc
|
|
|
|
|
.ThenBy(x => x.Name).Asc
|
|
|
|
|
.List();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
foreach (var item in list)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
NHibernateUtil.Initialize(item.ProductGroup);
|
2012-04-08 12:28:15 +00:00
|
|
|
|
NHibernateUtil.Initialize(item.ServiceTax);
|
|
|
|
|
NHibernateUtil.Initialize(item.Vat);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return list;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
|
|
|
|
public new IList<Product> List()
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
var list = _session.QueryOver<Product>()
|
2011-06-29 20:27:07 +00:00
|
|
|
|
.OrderBy(x => x.ProductGroup).Asc
|
|
|
|
|
.ThenBy(x => x.SortOrder).Asc
|
|
|
|
|
.ThenBy(x => x.Name).Asc
|
|
|
|
|
.List();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
foreach (var item in list)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
NHibernateUtil.Initialize(item.ProductGroup);
|
2012-04-08 12:28:15 +00:00
|
|
|
|
NHibernateUtil.Initialize(item.ServiceTax);
|
|
|
|
|
NHibernateUtil.Initialize(item.Vat);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return list;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public static IList<Product> List(Guid productGroupID)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
2011-01-31 20:33:22 +00:00
|
|
|
|
return (from product in session.QueryOver<Product>()
|
|
|
|
|
where product.ProductGroup.ProductGroupID == productGroupID
|
|
|
|
|
select product).List();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
|
|
|
|
|
public void UpdateSortOrder(IList<Product> list)
|
|
|
|
|
{
|
|
|
|
|
int order = 0;
|
|
|
|
|
Guid lastGroup = Guid.Empty;
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = list[i];
|
|
|
|
|
if (lastGroup != item.ProductGroup.ProductGroupID)
|
|
|
|
|
{
|
|
|
|
|
order = 0;
|
|
|
|
|
lastGroup = item.ProductGroup.ProductGroupID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
order += 5;
|
|
|
|
|
}
|
|
|
|
|
var product = _session.Get<Product>(item.ProductID);
|
|
|
|
|
product.SortOrder = order;
|
|
|
|
|
_session.Update(product);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|