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

68 lines
2.0 KiB
C#

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 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;
}
}
}
}