- CodeProjectORM.zip
- ORMApplicationServices
- ORMDatabase
- ORMDatabase.mdf
- ORMDatabase_log.ldf
- ORMDataModel
- ORMDataServices
- ORMNhiberateMaps
- ORMUtilities
- ORMWebApplicationMVC
- ORMWebApplicationMVC.sln
- ORMWebApplicationMVC.suo
- ORMWebApplicationMVC
- App_Data
- bin
- Antlr3.Runtime.dll
- Castle.Core.dll
- Iesi.Collections.dll
- Iesi.Collections.pdb
- NHibernate.ByteCode.Castle.dll
- NHibernate.ByteCode.Castle.xml
- NHibernate.dll
- NHibernate.xml
- ORMApplicationServices.dll
- ORMApplicationServices.pdb
- ORMDataModel.dll
- ORMDataModel.pdb
- ORMDataServices.dll
- ORMDataServices.pdb
- ORMNhibernateMaps.dll
- ORMNhibernateMaps.pdb
- ORMUtilities.dll
- ORMUtilities.pdb
- ORMWebApplicationMVC.dll
- ORMWebApplicationMVC.pdb
- Remotion.Data.Linq.dll
- Content
- DownArrow.gif
- Images
- DownArrow.gif
- SampleApplication.jpg
- UpArrow.gif
- Site.css
- themes
- base
- images
- ui-bg_flat_0_aaaaaa_40x100.png
- ui-bg_flat_75_ffffff_40x100.png
- ui-bg_glass_55_fbf9ee_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_glass_75_dadada_1x400.png
- ui-bg_glass_75_e6e6e6_1x400.png
- ui-bg_glass_95_fef1ec_1x400.png
- ui-bg_highlight-soft_75_cccccc_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_2e83ff_256x240.png
- ui-icons_454545_256x240.png
- ui-icons_888888_256x240.png
- ui-icons_cd0a0a_256x240.png
- jquery-ui.css
- UpArrow.gif
- Controllers
- Global.asax
- Global.asax.cs
- Helpers
- Models
- obj
- Debug
- ORMWebApplicationMVC.csproj
- ORMWebApplicationMVC.csproj.user
- ORMWebApplicationMVC.Publish.xml
- packages.config
- Properties
- Scripts
- Views
- Web.config
- Web.Debug.config
- Web.Release.config
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using ORMDataModel;
using ORMDataServices.DataServices;
using ORMDataServices.DataFactories.NHibernate;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using ORMUtilities;
namespace ORMDataServices.DataFactories.NHibernate
{
class NHCustomerService : NHibernateDataService, ICustomerDataService
{
PerformanceLogging _performanceLogging;
public NHCustomerService()
{
_performanceLogging = new PerformanceLogging();
}
/// <summary>
/// Get Customer Information
/// </summary>
/// <param name="customerID"></param>
/// <returns></returns>
public Customer GetCustomerInformation(Int32? customerID)
{
_performanceLogging.StartLogging("NHCustomerService.GetCustomerInformation");
if (SessionIsOpen == false) OpenSession();
Customer customer = Session.Get<Customer>(customerID);
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
return customer;
}
/// <summary>
/// Get Customer Information - with lock
/// </summary>
/// <param name="customerID"></param>
/// <returns></returns>
public Customer GetCustomerInformationWithLock(Int32? customerID)
{
_performanceLogging.StartLogging("NHCustomerService.GetCustomerInformationWithLock");
if (SessionIsOpen == false) OpenSession();
Customer customer = Session.Get<Customer>(customerID, LockMode.Upgrade);
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
return customer;
}
/// <summary>
/// Get Customers
/// </summary>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="totalCustomers"></param>
/// <returns></returns>
public List<Customer> GetCustomers(CustomerTransaction customerTransaction, out long totalCustomers)
{
_performanceLogging.StartLogging("NHCustomerService.GetCustomers");
string customerCode = customerTransaction.Customer.CustomerCode;
string companyName = customerTransaction.Customer.CompanyName;
string contactName = customerTransaction.Customer.ContactName;
if (SessionIsOpen == false) OpenSession();
int pageSize = customerTransaction.PageSize;
int pageNumber = customerTransaction.CurrentPageNumber;
ICriteria customerCriteria = Session.CreateCriteria(typeof(Customer))
.SetMaxResults(pageSize)
.SetFirstResult((pageNumber - 1) * pageSize);
ICriteria customerCountCriteria = Session.CreateCriteria(typeof(Customer))
.SetProjection(Projections.RowCount());
if (customerCode != null && customerCode.Trim().Length>0)
{
customerCriteria.Add(Expression.Like("CustomerCode", customerCode + "%"));
customerCountCriteria.Add(Expression.Like("CustomerCode", customerCode + "%"));
}
if (companyName != null && companyName.Trim().Length > 0)
{
customerCriteria.Add(Expression.Like("CompanyName", companyName + "%"));
customerCountCriteria.Add(Expression.Like("CompanyName", companyName + "%"));
}
if (contactName != null && contactName.Trim().Length > 0)
{
customerCriteria.Add(Expression.Like("ContactName", contactName + "%"));
customerCountCriteria.Add(Expression.Like("ContactName", contactName + "%"));
}
if (customerTransaction.SortExpression != null && customerTransaction.SortExpression.Trim().Length > 0)
{
if (customerTransaction.SortDirection == "DESC")
customerCriteria.AddOrder(Order.Desc(customerTransaction.SortExpression));
else
customerCriteria.AddOrder(Order.Asc(customerTransaction.SortExpression));
}
var multiResults = Session.CreateMultiCriteria()
.Add(customerCriteria)
.Add(customerCountCriteria)
.List();
IList customerList = (IList)multiResults[0];
IList counts = (IList)multiResults[1];
totalCustomers = (int)counts[0];
List<Customer> customers = new List<Customer>();
foreach (Customer customer in customerList)
{
customers.Add(customer);
}
CloseSession();
_performanceLogging.EndLogging("NHCustomerService.GetCustomers");
return customers;
}
/// <summary>
/// Validate Customer Code - existing customer
/// </summary>
/// <param name="customerCode"></param>
/// <param name="customerID"></param>
/// <returns></returns>
public List<Customer> ValidateCustomerCode(string customerCode, Int32? customerID)
{
_performanceLogging.StartLogging("NHCustomerService.ValidateCustomerCode1");
List<Customer> customer;
if (SessionIsOpen == false) OpenSession();
ICriteria criteria = Session.CreateCriteria(typeof(Customer))
.Add(Expression.Eq("CustomerCode", customerCode))
.Add(Expression.Not(Expression.Eq("CustomerID", customerID)));
customer = (List<Customer>)criteria.List<Customer>();
CloseSession();
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
return customer;
}
/// <summary>
/// Validate Customer Code - new customer
/// </summary>
/// <param name="customerCode"></param>
/// <returns></returns>
public List<Customer> ValidateCustomerCode(string customerCode)
{
_performanceLogging.StartLogging("NHCustomerService.ValidateCustomerCode2");
List<Customer> customer;
if (SessionIsOpen == false) OpenSession();
ICriteria criteria = Session.CreateCriteria(typeof(Customer))
.Add(Expression.Eq("CustomerCode", customerCode));
customer = (List<Customer>)criteria.List<Customer>();
CloseSession();
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
return customer;
}
/// <summary>
/// Insert Customer
/// </summary>
/// <param name="customer"></param>
public void InsertCustomer(Customer customer)
{
_performanceLogging.StartLogging("NHCustomerService.InsertCustomer");
Insert(customer);
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
}
/// <summary>
/// Insert Transaction Log
/// </summary>
/// <param name="transactionLog"></param>
public void InsertTransactionLog(TransactionLog transactionLog)
{
_performanceLogging.StartLogging("NHCustomerService.InsertTransactionLog");
Insert(transactionLog);
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
}
/// <summary>
/// Update Customer
/// </summary>
/// <param name="customer"></param>
public void UpdateCustomer(Customer customer)
{
_performanceLogging.StartLogging("NHCustomerService.UpdateCustomer");
Update(customer);
_performanceLogging.EndLogging("NHCustomerService.GetCustomerInformation");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Mark Caplin has specialized in Information Technology solutions for the past 30 years. Specializing in full life-cycle development projects for both enterprise-wide systems and Internet/Intranet based solutions.
For the past fifteen years, Mark has specialized in the Microsoft .NET framework using C# as his tool of choice. For the past four years Mark has been implementing Single Page Applications using the Angular platform.
When not coding, Mark enjoys playing tennis, listening to U2 music, watching Miami Dolphins football and watching movies in Blu-Ray technology.
In between all this, his wife of over 25 years, feeds him well with some great home cooked meals.
You can contact Mark at mark.caplin@gmail.com
...