Now let's create the business logic layer. The steps here are very similar to the steps in Chapter 4, Implementing a WCF Service in the Real World, so you can refer to that chapter for more details.
LINQNorthwindLogic
.LINQNorthwindDAL
and LINQNorthwindBDO
to this new project.Class1.cs
file.ProductLogic.cs
.ProductLogic
to be public.using
statements to the ProductLogic.cs
class file:using LINQNorthwindDAL; using LINQNorthwindBDO;
ProductLogic
class:ProductDAO productDAO = new ProductDAO();
GetProduct
to the ProductLogic
class:public ProductBDO GetProduct(int id) { return productDAO.GetProduct(id); }
UpdateProduct
to the ProductLogic
class:public bool UpdateProduct( ref ProductBDO productBDO, ref string message) { var productInDB = GetProduct(productBDO.ProductID); // invalid product to update if (productInDB == null) { message = "cannot get product for this ID"; return false; } // a product cannot be discontinued // if there are non-fulfilled orders if (productBDO.Discontinued == true && productInDB.UnitsOnOrder > 0) { message = "cannot discontinue this product"; return false; } else { return productDAO.UpdateProduct(ref productBDO, ref message); } }
Build the solution. We now have only one more step to go, that is, adding the service interface layer.