i have the following code which has some duplication
private List<SelectListItem> GetDeskList(int deskId)
{
List<Desk> apps = Model.GetDesks();
List<SelectListItem> dropdown = apps.ConvertAll(c => new SelectListItem
{
Selected = c.Id == deskId,
Text = c.Name,
Value = c.Id.ToString()
}).ToList();
dropdown.Insert(0, new SelectListItem());
return dropdown;
}
private List<SelectListItem> GetRegionList(int regionId)
{
List<Region> apps = Model.GetRegions();
List<SelectListItem> dropdown = apps.ConvertAll(c => new SelectListItem
{
Selected = c.Id == regionId,
Text = c.Name,
Value = c.Id.ToString()
}).ToList();
dropdown.Insert(0, new SelectListItem());
return dropdown;
}
and a few more like it with a similar pattern. what is the best way to refactor this to avoid duplication