Creating the business logic layer

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.

  1. Right click on the solution item and select Add | New Project.... Add a class library project with the name LINQNorthwindLogic.
  2. Add a project reference to LINQNorthwindDAL and LINQNorthwindBDO to this new project.
  3. Delete the Class1.cs file.
  4. Add a new class file ProductLogic.cs.
  5. Change the new class ProductLogic to be public.
  6. Add the following two using statements to the ProductLogic.cs class file:
    using LINQNorthwindDAL;
    using LINQNorthwindBDO;
  7. Add the following class member variable to the ProductLogic class:
    ProductDAO productDAO = new ProductDAO();
  8. Add the following new method GetProduct to the ProductLogic class:
    public ProductBDO GetProduct(int id)
    {
        return productDAO.GetProduct(id);
    }
  9. Add the following new method 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset