Monday, July 28, 2008

Creating a Business Logic Layer

The Data Access Layer (DAL) created in the first tutorial cleanly separates the data access logic from the presentation logic. However, while the DAL cleanly separates the data access details from the presentation layer, it does not enforce any business rules that may apply


In this tutorial we'll see how to centralize these business rules into a Business Logic Layer (BLL) that serves as an intermediary for data exchange between the presentation layer and the DAL. In a real-world application, the BLL should be implemented as a separate Class Library project; however, for these tutorials we'll implement the BLL as a series of classes in our App_Code folder in order to simplify the project structure. Figure 1 illustrates the architectural relationships among the presentation layer, BLL, and DAL.

Partial code for Business Logic Layer



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for blayer
///

public class blayer
{
public blayer()
{
//
// TODO: Add constructor logic here
//
}

///
/// insert records into database
///

public int insert(string title, string description)
{

person p1 = new person();
try
{
return p1.insert(title, description);
}
catch (Exception ex)
{
throw;
}
finally
{
p1 = null;
}
}

///
/// update records into database
///

public int update(int id, string title, string description)
{
person p1 = new person();

try
{
return p1.update(id, title, description);
}

catch
{
throw;
}

finally
{
p1 = null;
}
}
///
/// Shows records from database
///

public DataTable show()
{
person p1 = new person();

try
{
return p1.show();
}
catch
{
throw;
}
finally
{
p1 = null;

}

}
public DataTable show1(int id)
{
person p1 = new person();

try
{
return p1.show1(id);
}
catch
{
throw;
}
finally
{
p1 = null;
}
}
///
/// Delete record from database
///

public int delete(int id)
{
person p1 = new person();

try
{
return p1.delete(id);
}

catch
{
throw;

}
finally
{
p1 = null;

}
}
}

No comments: