public ActionResult Create(Section section) { if (ModelState.IsValid) { ds.Create(section); return RedirectToAction("Index"); } return View(section); }
// Method for updating sections public void Update(Section section) { dc.Entry(section).State = EntityState.Modified; dc.SaveChanges(); }
// Method for creating sections public void Create(Section section) { dc.Sections.Add(section); dc.SaveChanges(); }
// Displays the Edit view public ActionResult Edit(int id = 0) { Section Section = ds.Find(id); if (Section == null) { return HttpNotFound(); } // query users to a list var courseResults = (from c in dc.Courses select c).ToList(); // query sessions to a list var sessionResults = (from s in dc.Sessions select s).ToList(); // populate user list to drop down menu IEnumerable<SelectListItem> courses; courses = courseResults.Select(a => new SelectListItem { Value = a.Id.ToString(), Text = a.Name }); // populate session list to drop down menu IEnumerable<SelectListItem> sessions; sessions = sessionResults.Select(a => new SelectListItem { Value = a.Id.ToString(), Text = a.Name }); var model = new Section(); model.Id = id; //ViewBag.SessionId = new SelectList(sessions, "Value", "Text", Section.SessionId); ViewBag.CourseList = courses; // set user list to ViewBag ViewBag.SessionList = sessions; // set session list to View Bag return View(model); }