using System; using System.Data; using System.Collections.Generic; public class CustomerBusinessLogicLayer { //need default constructor for View public CustomerBusinessLogicLayer() { } // Returns an sorted list of all customers (with all fields included) public List GetCustomers() { return GetCustomers("LastName"); } // Returns a sorted list of all customers (with all fields included) public List GetCustomers(String sortExpression) { List customers = new List(); DataSet ds = CustomerDataAccessLayer.GetCustomers(); foreach (DataRow row in ds.Tables[0].Rows) { customers.Add(new Customer((int)row["CustomerId"], (String)row["FirstName"], (String)row["LastName"], (decimal)row["CreditLimit"], (String)row["PhoneNumber"])); } customers.Sort(new CustomerComparer(sortExpression)); return customers; } // Returns one customer with all fields filled in public List GetCustomersById(int id) { List customers = new List(); DataSet ds = CustomerDataAccessLayer.GetCustomerById(id); foreach (DataRow row in ds.Tables[0].Rows) { customers.Add(new Customer((int)row["CustomerId"], (String)row["FirstName"], (String)row["LastName"], (decimal)row["CreditLimit"], (String)row["PhoneNumber"])); } return customers; } // Updates an existing customer in database (note: business logic omitted to simplify example) public void UpdateCustomer(String firstName, String lastName, decimal creditLimit, string phoneNumber, int customerId) { CustomerDataAccessLayer.UpdateCustomer(customerId, firstName, lastName, creditLimit, phoneNumber); } // Inserts a new customer in database (note: business logic omitted to simplify example) public void InsertCustomer(int customerId, String firstName, String lastName, decimal creditLimit, string phoneNumber) { CustomerDataAccessLayer.InsertCustomer(customerId, firstName, lastName, creditLimit, phoneNumber); } // Deletes an existing customer from database (note: business logic omitted to simplify example) public void DeleteCustomer(int customerId) { CustomerDataAccessLayer.DeleteCustomer(customerId); } }