我有这个简单的应用程序正在检查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
段的代码?或者我应该尝试不同的方法? 谢谢!