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

76 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
using Tanshu.Accounts.SqlDAO;
using Tanshu.Accounts.Entities;
using NHibernate.Criterion;
namespace Tanshu.Accounts.Repository
{
public class CustomerBI
{
public Customer GetCustomer(int customerID)
{
using (var session = SessionManager.Session)
{
return session.Get<Customer>(customerID);
}
}
public IList<Customer> GetCustomers()
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<Customer>().List<Customer>();
}
}
public IList<Customer> GetSingleCustomers(int customerID)
{
using (var session = SessionManager.Session)
{
return session.CreateCriteria<Customer>()
.Add(Restrictions.Eq("CustomerID", customerID))
.List<Customer>();
}
}
public void Update(Customer customer)
{
using (var session = SessionManager.Session)
{
session.Update(customer);
}
}
public bool Delete(int customerID)
{
using (var session = SessionManager.Session)
{
session.Delete(new Customer() { CustomerID = customerID });
return true;
}
}
public void Insert(Customer customer)
{
using (var session = SessionManager.Session)
{
session.Save(customer);
}
}
public IList<Customer> GetFilteredCustomers(Dictionary<string, string> filter)
{
using (var session = SessionManager.Session)
{
string name = string.Format("%{0}%", filter["Universal"]);
return session.CreateCriteria<Customer>()
.Add(Restrictions.Like("Name", name))
.List<Customer>();
}
}
}
}