// // GET: /Presentation/Create public ActionResult Add(string id) { var conference = YouConfDataContext.GetConference(id); if (conference == null) { return HttpNotFound(); } ModelState.Remove("id"); var presentation = new Presentation() { Id = DateTime.Now.Ticks }; ViewBag.Conference = conference; ViewBag.Speakers = conference.Speakers; return View(presentation); }
public ActionResult Add(string conferenceHashTag, long[] speakerIds, Presentation presentation) { var conference = YouConfDataContext.GetConference(conferenceHashTag); if (conference == null) { return HttpNotFound(); } if (ModelState.IsValid) { //Convert the start time to UTC before storing presentation.StartTime = ConvertToUtc(presentation.StartTime, conference.TimeZoneId); PopulateSpeakers(conference, presentation, speakerIds); conference.Presentations.Add(presentation); YouConfDataContext.UpsertConference(conference.HashTag, conference); return RedirectToAction("Details", "Conference", new { hashTag = conferenceHashTag }); } ViewBag.Conference = conference; ViewBag.Speakers = conference.Speakers; return View(presentation); }
private void PopulateSpeakers(Conference conference, Presentation presentation, long[] speakerIds) { presentation.Speakers.Clear(); //Could look at creating a custom model binder here, but doing it simple for now.... if (speakerIds == null) return; foreach (var speakerId in speakerIds) { var speaker = conference.Speakers.First(x => x.Id == speakerId); presentation.Speakers.Add(speaker); } }
public ActionResult Edit(string conferenceHashTag, long[] speakerIds, Presentation presentation) { var conference = YouConfDataContext.GetConference(conferenceHashTag); if (conference == null) { return HttpNotFound(); } if (ModelState.IsValid) { var currentPresentation = conference.Presentations.FirstOrDefault(x => x.Id == presentation.Id); if (currentPresentation == null) { return HttpNotFound(); } //Convert the start time to UTC before storing presentation.StartTime = ConvertToUtc(presentation.StartTime, conference.TimeZoneId); PopulateSpeakers(conference, presentation, speakerIds); //Overwrite the old Presentation details with the new conference.Presentations[conference.Presentations.IndexOf(currentPresentation)] = presentation; YouConfDataContext.UpsertConference(conferenceHashTag, conference); return RedirectToAction("Details", "Conference", new { hashTag = conferenceHashTag }); } ViewBag.Conference = conference; ViewBag.Speakers = conference.Speakers; return View(presentation); }