narsil/Tanshu.Accounts.Repository/ProductGroupBI.cs
tanshu 3ca8b29e04 Regression: BillItemKey added the compare methods back
Regression: PrintLocation added the compare methods back
Breaking: Kot.Code is now integers
Breaking: Kot Update is now via Stored Procedure to get DB Values
Breaking: Reprints Insert is now via Stored Procedure to get DV Values
Breaking: Voucher.BillID and KotID are now integers
Breaking: Voucher Insert/Update is now via Stored Procedures to get DV Values also Dirty Checking for Voucher has been overwritten to set dirty for LastEditDate update
Fix: Login forms simplified
Feature: PrintLocation and Products are cached application wide.
2014-11-02 13:33:31 +05:30

74 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Tanshu.Accounts.Entities;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Transform;
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)
{
_session.FlushMode = FlushMode.Never;
return _session.QueryOver<ProductGroup>()
.Where(query)
.OrderBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
}
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();
}
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)
{
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
var productGroup = _session.Get<ProductGroup>(item.ProductGroupID);
productGroup.SortOrder = i;
_session.Update(productGroup);
}
}
}
}