示例#1
0
 //
 // GET: /Speaker/Create
 public ActionResult Add(string id)
 {
     var speaker = new Speaker()
     {
         Id = DateTime.Now.Ticks
     };
     //We want the id hidden field to be the SpeakerId, but if we don't remove it from ModelState here it will be the conference Id. See http://stackoverflow.com/questions/4710447/asp-net-mvc-html-hiddenfor-with-wrong-value
     ModelState.Remove("id");
     ViewBag.ConferenceId = id;
     return View(speaker);
 }
示例#2
0
        public ActionResult Add(string conferenceHashTag, Speaker speaker)
        {
            if (ModelState.IsValid)
            {
                var conference = YouConfDataContext.GetConference(conferenceHashTag);
                if (conference == null)
                {
                    return HttpNotFound();
                }

                conference.Speakers.Add(speaker);
                YouConfDataContext.UpsertConference(conference.HashTag, conference);
                return RedirectToAction("Details", "Conference", new { hashTag = conferenceHashTag });
            }

            ViewBag.ConferenceId = conferenceHashTag;
            return View(speaker);
        }
示例#3
0
        public ActionResult Edit(long id, string conferenceHashTag, Speaker speaker)
        {
            if (ModelState.IsValid)
            {
                var conference = YouConfDataContext.GetConference(conferenceHashTag);
                if (conference == null)
                {
                    return HttpNotFound();
                }

                var currentSpeaker = conference.Speakers.FirstOrDefault(x => x.Id == id);
                if (currentSpeaker == null)
                {
                    return HttpNotFound();
                }

                //Overwrite the old speaker details with the new
                conference.Speakers[conference.Speakers.IndexOf(currentSpeaker)] = speaker;

                YouConfDataContext.UpsertConference(conferenceHashTag, conference);
                return RedirectToAction("Details", "Conference", new { hashTag = conferenceHashTag });
            }

            ViewBag.ConferenceId = conferenceHashTag;
            return View(speaker);
        }