69617949bd
Important! : This version will not work. It is pre-alpha and saved in case of catastrophic failure Refactor: Remove dependency on Fluent Nhibernate. Refactor: All Primary keys are now Guids. Refactor: Class Mappings changed from AutoMap to Explicit Mappings. Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs. Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function. Chore: Removed Advance and Payments options.
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq.Expressions;
|
|
using Tanshu.Accounts.Entities;
|
|
using NHibernate;
|
|
|
|
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)
|
|
{
|
|
return _session.QueryOver<ProductGroup>()
|
|
.Where(query)
|
|
.OrderBy(x => x.SortOrder).Asc
|
|
.ThenBy(x => x.Name).Asc
|
|
.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)
|
|
{
|
|
int order = 0;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var item = list[i];
|
|
var productGroup = _session.Get<ProductGroup>(item.ProductGroupID);
|
|
productGroup.SortOrder = order;
|
|
_session.Update(productGroup);
|
|
}
|
|
}
|
|
}
|
|
}
|