public ActionResult Create(Play play) { if (ModelState.IsValid) { context.Plays.Add(play); ApplyAllocatedVolunteers(play); context.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PossibleStudents = context.Students; _initialisesVolunteerAllocationView.Initialise(ViewBag, context); return View(play); }
static object ImportPlay(SceneCRM context, Student student, CourseType courseType, string termName, string termYear, string productionName, string playName, string dramaturg, string director, params string[] actors) { object returnValue = null; var term = context.Terms.FindOrMake(termName, context); var course = context.Courses.FindOrMake(courseType, term, termYear, context); if (course != null) { var attendance = new CourseAttendance() { Student = student, Course = course, Completed = true }; Production production = context.Productions.FindOrMake(productionName, context); if (!String.IsNullOrWhiteSpace(playName)) { var play = new Play() { Student = student, Title = playName }; if (production != null) play.Production = production; attendance.Play = play; student.Plays.Add(play); AddPlayVolunteer(context, play, dramaturg, Jobs.Dramaturg); AddPlayVolunteer(context, play, director, Jobs.Director); foreach (var actor in actors) { AddPlayVolunteer(context, play, actor, Jobs.Actor); } returnValue = play; } else { AddCourseVolunteer(context, course, dramaturg, Jobs.Dramaturg); AddCourseVolunteer(context, course, director, Jobs.Director); foreach (var actor in actors) { AddCourseVolunteer(context, course, actor, Jobs.Actor); } returnValue = course; } student.CourseAttendances.Add(attendance); } return(returnValue); }
static void AddPlayVolunteer(SceneCRM context, Play play, string volunteerName, string jobTitle) { var vol = context.Volunteers.FindOrMake(volunteerName, context); if (vol == null) return; var job = context.Jobs.FindOrMake(jobTitle, context); if (!vol.PlayVolunteers.Any(cv => cv.Job == job && cv.Play == play)) { context.PlayVolunteers.Add(new PlayVolunteer() { Play = play, Volunteer = vol, Job = job }); } context.SaveChanges(); }
private void ApplyAllocatedVolunteers(Play play) { var volunteerAllocations = _interpretsPostedVolunteerAllocations.Interpret(Request.Form); play.PlayVolunteers.Clear(); foreach (var volunteerAllocation in volunteerAllocations) { play.PlayVolunteers.Add(new PlayVolunteer { VolunteerId = volunteerAllocation.VolunteerId, JobId = volunteerAllocation.JobId, Notes = volunteerAllocation.Notes }); } }
public ActionResult Edit(Play play) { if (ModelState.IsValid) { context.Entry(play).State = EntityState.Modified; ApplyAllocatedVolunteers(play); context.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PossibleStudents = context.Students; _initialisesVolunteerAllocationView.Initialise(ViewBag, context, play.PlayVolunteers.Select(pv => new VolunteerAllocation(pv.VolunteerId, pv.JobId, pv.Notes))); return View(play); }