narsil/Tanshu.Accounts.Repository/BusinessLayer/ProductGroupBI.cs

77 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.SqlDAO;
using NHibernate.Criterion;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class ProductGroupBI
{
public ProductGroup GetProductGroup(int productGroupID)
{
using (var session = SessionManager.Session)
{
return session.Get<ProductGroup>(productGroupID);
}
}
public ProductGroup GetProductGroupByName(string name)
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<ProductGroup>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<ProductGroup>();
}
}
public void Insert(ProductGroup productGroup)
{
using (var session = SessionManager.Session)
{
session.Save(productGroup);
}
}
public void Update(ProductGroup productGroup)
{
using (var session = SessionManager.Session)
{
session.Update(productGroup);
}
}
public IList<ProductGroup> GetProductGroups()
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<ProductGroup>()
.AddOrder(Order.Asc("Name"))
.List<ProductGroup>();
}
}
public IList<string> GetProductGroupTypes()
{
using (var session = SessionManager.Session)
{
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(int 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;
}
}
}
}