public ActionResult ShowEditIncidentForm() { // Attention 27 - Create and configure a view model object var form = new IncidentEditForm(); // Attention 28 - SelectList objects //form.OffenceList = new SelectList(this.Offences, "Id", "offenceTerm"); // Attention 29 - Carefully study the PlanCourses view return(View(form)); }
// ############################################################ public IncidentWithDetails IncidentEditForm(IncidentEditForm newItem) { // Attempt to fetch the object var o = ds.Incidents.Find(newItem.InstructorId); o = ds.Incidents.Include("Students").Include("Instructor").SingleOrDefault(a => a.Id == newItem.id); if (o == null) { // Problem - item was not found, so return return(null); } else { // Update the object with the incoming values ds.Entry(o).CurrentValues.SetValues(newItem); ds.SaveChanges(); // Prepare and return the object return(Mapper.Map <IncidentWithDetails>(o)); } }