Exemplo n.º 1
0
        public ActionResult Create(Section section)
        {
            if (ModelState.IsValid)
            {
                ds.Create(section);
                return RedirectToAction("Index");
            }

            return View(section);
        }
Exemplo n.º 2
0
 // Method for updating sections
 public void Update(Section section)
 {
     dc.Entry(section).State = EntityState.Modified;
     dc.SaveChanges();
 }
Exemplo n.º 3
0
 // Method for creating sections
 public void Create(Section section)
 {
     dc.Sections.Add(section);
     dc.SaveChanges();
 }
Exemplo n.º 4
0
        // 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);
        }