Introduction
The data access layer, described in the first section of this tutorial, is a clear distinction between presentation logic and data access logic, as in the case of Layer, the following referred to as DAL. However, even if the DAL separates the details of data access from the presentation layer, it cannot handle any business rules. For example, we may not want the "category number" or "vendor number" of products in the product table that are marked "deactivated" to be updated; We may also need to apply some seniority rules, such as we don't want to be managed by someone who is less than our own qualifications. Another common scenario is authorization, for example, that only users with special privileges can delete a product or change the unit price.
We can actually think of the business Logic layer (Business Logic Layer, BLL) as a bridge between the data access layer and the presentation layer, and in this section we'll discuss how to integrate these business rules into a BLL. It should be explained that in a real-world application, BLL is implemented in the form of class libraries, but in order to simplify the structure of the project, in this tutorial we will implement BLL as a series of classes in the App_Code folder. The graph has always shown the structural relationship between the presentation layer, the BLL, and the DAL.
Figure one: BLL separates the presentation layer from the Dal and joins the business rules
First step: Create BLL Class
Our BLL consists of 4 classes, each of which corresponds to a TableAdapter in the DAL, which are read, inserted, modified, and deleted from their TableAdapter to apply the appropriate business rules.
To make a clearer distinction between dal and BLL classes, we created two subfolders in the App_Code folder, named Dal and BLL respectively. You just need to right-click the App_Code folder in Solution Explorer (Solution Explorer) and select New folder to create a new subfolder. After the two folders have been built, move the typed dataset (Typed DataSet) created in the first section to the Dal folder.
Then, create 4 class files in the BLL folder. Again, you just need to right-click the BLL folder in the Solution Explorer (Solution Explorer) and select New Item, and then select Class template in the pop-up dialog box to create a new class file. Each of these four files is named Productsbll, CATEGORIESBLL, SUPPLIERSBLL, and EMPLOYEESBLL.
Figure Two: Add 4 new classes to the BLL folder