// Attention 26 - Edit an employee's job duties
// GET: Matches/EmployeeAndJobDuties/5
// Prepare and display the HTML Form to enable editing an employee's job duties
public ActionResult EmployeeAndJobDuties(int?id)
{
// Attempt to fetch the matching object
var o = m.EmployeeGetByIdWithDetail(id.GetValueOrDefault());
if (o == null)
{
return(HttpNotFound());
}
else
{
// Create a form, based on the fetched matching object
var form = m.mapper.Map <EmployeeEditJobDutiesForm>(o);
// For the multi select list, configure the "selected" items
// Notice the use of the Select() method,
// which allows us to select/return/use only some properties from the source
var selectedValues = o.JobDuties.Select(jd => jd.Id);
// For clarity, use the named parameter feature of C#
form.JobDutyList = new MultiSelectList
(items: m.JobDutyGetAll(),
dataValueField: "Id",
dataTextField: "FullName",
selectedValues: selectedValues);
return(View(form));
}
}