2012-07-04 1 views
0

ASP.NET Web Forms/C#을 사용하고 있습니다.코드 뒤에서 비즈니스 로직 계층 클래스로 함수 이동

DropDownList 선택에 따라 도시 DropDownList을 채우는 내 code behind에이 기능이 있습니다.

여기 내 기능입니다.

public void CityFill(int index,int id) 
     { 
      //This function calls GetCities method which will get all cities of a state. 
      var city = CustomerBLL.GetCities(index); 



      //If id=0 then clear all dropdown before filling 
      //or else they get appended. 
      if (id == 0) 
      { 
       NewCustomerddlResidentialCity.Items.Clear(); 
       NewCustomerddlOfficeCity.Items.Clear(); 
       NewCustomerddlNativeCity.Items.Clear(); 
       NewCustomerddlNomineeCity.Items.Clear(); 
      } 
      else 
      { 
       //If 1 then clear residential city 
       if(id==1) 
        NewCustomerddlResidentialCity.Items.Clear(); 

       //If 2 then clear Office city. 
       if(id==2) 
        NewCustomerddlOfficeCity.Items.Clear(); 

       //If id=3 then clear Native City. 
       if(id==3) 
        NewCustomerddlNativeCity.Items.Clear(); 

       //If id=4 then clear Nominee City 
       if(id==4) 
        NewCustomerddlNomineeCity.Items.Clear(); 
      } 

      //Loop through all the cities in st object 
      foreach (var c in city) 
      { 
       //If id=0 then fill all dropdowns 
       if (id == 0) 
       { 
        NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim()); 
        NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim()); 
        NewCustomerddlNativeCity.Items.Add(c.city_name.Trim()); 
        NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim()); 
       } 
       else 
       { 
        //If 1 then fill Res City 
        if(id==1) 
        NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim()); 

        //If 2 then fill Off City 
        if(id==2) 
        NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim()); 

        //If 3 then fill nat city 
        if(id==3) 
        NewCustomerddlNativeCity.Items.Add(c.city_name.Trim()); 

        //If 4 then fill nominee city 
        if(id==4) 
        NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim()); 

       } 
      } 
     } 

인수에 전달되는 인수는 index 및 id입니다. 인덱스는 이고 상태는 DropDownList입니다. ID는 어떤 도시 DropDownList을 채워야하는지입니다. 여기

내가 BLL 클래스 뒤에 코드에서 함수를 이동해야 BLL 클래스

namespace CwizBankApp 
{ 
    public class CustomerBLL 
    { 
     public IList<mem_city> GetCities(int index) 
     { 
      using (var db = new DataClasses1DataContext()) 
      { 
       var city = db.mem_cities.Where(c => c.state_id.Equals(index)).ToList(); 
       return city; 
      } 
     } 
    } 
} 

입니다.

어떻게해야합니까?

누구든지 나를 도와 줄 수 있습니까? 모든 제안을 환영합니다.

+0

bl 클래스에서 UI 작업을 수행 할 수 없어야합니다. 코드에 어떤 문제가 있습니까? –

+0

@SteveB이 코드는 작동하고 있으므로 코드 뒤에 만 사용해야한다고 권장합니까? 괜찮습니까? – freebird

+0

각 레이어의 책임은 다음과 같습니다. BLL 계층은 비즈니스 로직, DAL 데이터 액세스 및 UI를 처리해야합니다. 이 경우 표시되는 코드는 올바르게 이해하면 일부 비즈니스 가치를 기반으로 UI를 설정하는 방법입니다. 이 경우 UI 작업이라고 생각하므로 내 경우에는 코드가 정상적으로 보입니다. –

답변

1

나는 BLL 클래스에서 그렇게하지 않을 것을 제안합니다. 프리젠 테이션 로직에서 데이터 액세스 로직을 분리하도록 설계된 것처럼 BLL을 IT에 강요하지 마십시오.

+0

코드 뒤에서 내가 지금하고있는 일은 괜찮습니다. 어떻게 생각하십니까? 고마워요. – freebird

+0

예. 맞습니다. 코드 자체에서 최적화 할 수 있습니다. –

+0

도움을 주셔서 감사합니다 :) – freebird