我有這個簡單的應用程序正在檢查Employee Position,然後根據某些業務規則返回html表(實際上我使用repeater而不是html表)。 ,但後來我知道如果員工在公司中有2個職位,並且我需要根據兩個職位的信息返回html表。現在我有位置listPositions
的列表,其中可能包含多於1個職位。我的代碼(業務邏輯)是這樣的:使用DataSource和DataBinding重構代碼
Dictionary<string, Action> actions = new Dictionary<string, Action>()
{
{"Admin", new Action(() =>
{rptEmployees.DataSource = spc.GetEmployeeInfo(Models.PhoneNumbers.AllEmployee);
rptEmployees.DataBind();}) },
{"OfficeDirector", new Action(() =>
{rptEmployees.DataSource = spc.GetEmployeeInfo(Models.PhoneNumbers.OfficeEmployee);
rptEmployees.DataBind();})},
{"RegularUser", new Action(() =>
{rptEmployees.DataSource = spc.GetEmployeeInfo(Models.PhoneNumbers.OfficeDepartmentEmployee);
rptEmployees.DataBind();})}
};
我的方法GetemployeeInfo()
正在SPListItemCollection
作爲參數和返回,我結合牛逼EmployeeInfo對象重複使用rptEmployees
。代碼(業務邏輯)的
休息我想應該是這樣的:
foreach (var position in listPositions)
{
if (actions.ContainsKey(position))
{
actions[position]();
}
}
但很明顯的錯誤,因爲當出現在列表中超過1點的位置,這部分代碼首先結合repeater
與第一個位置和第二個綁定後的信息都會丟失。 有沒有任何posibility重構業務邏輯和獲取兩個職位的信息,而不改變Dictionary
段的代碼?或者我應該嘗試不同的方法? 謝謝!