narsil/Tanshu.Accounts.Repository/BusinessLayer/ProductBI.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

86 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class ProductBI : FluentGenericBase<Product>
{
public ProductBI()
: base()
{ }
public ProductBI(bool beginTransaction)
: base(beginTransaction)
{ }
public ProductBI(ISession session)
: base(session)
{ }
public ProductBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public Product Get(string nameAndUnits)
{
return Get(x => x.Name + " (" + x.Units + ")" == nameAndUnits);
}
public new IList<Product> List(Expression<Func<Product, bool>> query)
{
var list = Query()
.Where(query)
.OrderBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
foreach (var item in list)
{
NHibernateUtil.Initialize(item.ProductGroup);
NHibernateUtil.Initialize(item.Tax);
}
return list;
}
public new IList<Product> List()
{
var list = Query()
.OrderBy(x => x.ProductGroup).Asc
.ThenBy(x => x.SortOrder).Asc
.ThenBy(x => x.Name).Asc
.List();
foreach (var item in list)
{
NHibernateUtil.Initialize(item.ProductGroup);
NHibernateUtil.Initialize(item.Tax);
}
return list;
}
public static List<ProductDisplaySmall> GetFilteredProducts(Dictionary<string, string> filter)
{
throw new NotImplementedException();
}
public static List<ProductDisplaySmall> GetUnFilteredProducts()
{
Dictionary<string, string> filter = new Dictionary<string, string>();
filter.Add("Name", "");
filter.Add("Type", "");
return GetFilteredProducts(filter);
}
public static IList<Product> List(int productGroupID)
{
using (var session = SessionManager.Session)
{
return (from product in session.QueryOver<Product>()
where product.ProductGroup.ProductGroupID == productGroupID
select product).List();
}
}
}
}