narsil/Tanshu.Accounts.Repository/BusinessLayer/ProductBI.cs
2011-03-12 17:12:02 +05:30

90 lines
2.8 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;
namespace Tanshu.Accounts.Repository
{
public static class ProductBI
{
public static void Insert(Product product)
{
using (var session = SessionManager.Session)
{
session.Save(product);
}
}
public static void Update(Product product)
{
using (var session = SessionManager.Session)
{
session.Update(product);
}
}
public static bool Delete(int productID)
{
using (var session = SessionManager.Session)
{
session.Delete(new Product() { ProductID = productID });
return true;
}
}
public static Product GetProductFromName(string nameAndUnits)
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<Product>()
.Add(Expression.Eq("Name + ' (' + Units + ')'", nameAndUnits))
.UniqueResult<Product>();
}
}
public static Product GetProduct(int productID)
{
using (var sessioin = SessionManager.Session)
{
return sessioin.Get<Product>(productID);
}
}
public static decimal GetProductStock(DateTime date, int productID, int? voucherID)
{
throw new NotImplementedException();
}
public static IList<Product> GetProducts()
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<Product>()
.List<Product>();
}
}
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> GetProducts(int productGroupID)
{
using (var session = SessionManager.Session)
{
return (from product in session.QueryOver<Product>()
where product.ProductGroup.ProductGroupID == productGroupID
select product).List();
}
}
}
}