- inmemorydal_src.zip
- InMemoryDal
- InMemoryDal.BusinessLogic
- InMemoryDal.Entities
- InMemoryDal.Helpers
- InMemoryDal.InMemoryData
- InMemoryDal.Interfaces
- InMemoryDal.sln
- InMemoryDal.Tests
- AuthoringTests.txt
- bin
- Debug
- InMemoryDal.BusinessLogic.dll
- InMemoryDal.BusinessLogic.pdb
- InMemoryDal.Entities.dll
- InMemoryDal.Entities.pdb
- InMemoryDal.Helpers.dll
- InMemoryDal.Helpers.pdb
- InMemoryDal.InMemoryData.dll
- InMemoryDal.InMemoryData.pdb
- InMemoryDal.Interfaces.dll
- InMemoryDal.Interfaces.pdb
- InMemoryDal.Tests.dll
- InMemoryDal.Tests.pdb
- NLog.dll
- NLog.xml
- CustomerLogicTest.cs
- InMemoryDal.Tests.csproj
- OrderLogicTest.cs
- Properties
- InMemoryDal.vsmdi
- InMemoryDal1.vsmdi
- InMemoryDal2.vsmdi
- LocalTestRun.testrunconfig
- TestResults
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using InMemoryDal.Entities;
using InMemoryDal.Interfaces;
using InMemoryDal.Helpers;
namespace InMemoryDal.Logic
{
/// <summary>
/// Customer BL
/// </summary>
/// <remarks>
/// GB 28/10/2008
/// </remarks>
public class CustomerLogic
{
string _connectionString;
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public CustomerLogic(string connectionString)
{
_connectionString = connectionString;
}
public CustomerLogic()
{
// gets connectin string from configuration
}
public Customer CreateCustomer(Guid id, String firstname, String lastname, String address)
{
Customer customer = new Customer();
customer.Id = id;
if (firstname == string.Empty)
{
throw new ArgumentException("Firstname empty.");
}
if (lastname == string.Empty)
{
throw new ArgumentException("Lastname empty.");
}
customer.Firstname = firstname;
customer.Lastname = lastname;
customer.Address = address;
return customer;
}
public Customer NewCustomer(String firstname, String lastname, String address)
{
Customer customer = CreateCustomer(Guid.NewGuid(), firstname, lastname, address);
//customer.Versione = new byte[] { };
return customer;
}
public Customer AddCustomer(String firstname, String lastname, String address)
{
Customer entity = NewCustomer(firstname, lastname, address);
Save(entity);
logger.Trace(entity.ToString());
entity = GetById(entity.Id);
return entity;
}
public Customer UpdateCustomer(Guid id, String firstname, String lastname, String address, byte[] versione)
{
Customer entitySulDb = GetById(id);
Customer entity = CreateCustomer(id, firstname, lastname, address);
Save(entity);
logger.Trace(entity.ToString());
return GetById(id);
}
public void DeleteCustomer(Guid id)
{
OrderLogic orderLogic = new OrderLogic();
List<Order> orders = orderLogic.GetByCustomerId(id);
if (orders.Count != 0)
{
throw new ArgumentException("Can't delete customer, it has orders.");
}
Customer ent = GetById(id);
Delete(ent);
logger.Trace(ent.ToString());
}
public Customer GetById(Guid id)
{
List<Customer> lis;
using (IOrdersSession sess = GBDipendencyInjection.GetSession())
{
lis = sess.DbCustomers.Search(id, string.Empty, string.Empty, string.Empty, CreateCustomer);
}
if (lis.Count == 1)
return lis[0];
else if (lis.Count == 0)
return null;
else
throw new ArgumentException("DB read error");
}
public List<Customer> GetAll()
{
List<Customer> lis;
using (IOrdersSession sess = GBDipendencyInjection.GetSession())
{
lis = sess.DbCustomers.Search(Guid.Empty, string.Empty, string.Empty, string.Empty, CreateCustomer);
}
return lis;
}
private void Save(Customer customer)
{
using (IOrdersSession sess = GBDipendencyInjection.GetSession())
{
IDbTransaction trans = sess.BeginTransaction();
sess.Save(customer);
trans.Commit();
}
}
private void Delete(Customer customer)
{
using (IOrdersSession sess = GBDipendencyInjection.GetSession())
{
IDbTransaction trans = sess.BeginTransaction();
sess.Delete(customer);
trans.Commit();
}
}
}
}
|
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.
Software architect. At present working on C# development, with mainly Asp.net Ajax and MVC user inteface. Particularly interested in OOP, test driven, agile development.