Пример #1
0
        public ActionResult Create(Student student)
        {
            if (ModelState.IsValid)
            {
                ds.Create(student);
                return RedirectToAction("Index");
            }

            return View(student);
        }
Пример #2
0
 // Method for updating students
 public void Update(Student student)
 {
     dc.Entry(student).State = EntityState.Modified;
     dc.SaveChanges();
 }
Пример #3
0
        // Displays the Edit view
        public ActionResult Edit(int id)
        {
            Student student = ds.Find(id);
            if (student == null)
            {
                return HttpNotFound();
            }

            // query users to a list
            var userResults = (from u in dc.UserProfiles
                               select u).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> users;
            users = userResults.Select(a => new SelectListItem
            {
                Value = a.UserId.ToString(),
                Text = a.UserName
            });

            // 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 Student();
            model.UserId = id;
            ViewBag.SessionId = new SelectList(sessions, "Value", "Text", student.SessionId);
            ViewBag.UserList = users;       // set user list to ViewBag
            ViewBag.SessionList = sessions; // set session list to View Bag
            return View(model);
        }
Пример #4
0
 // Method for creating students
 public void Create(Student student)
 {
     dc.Students.Add(student);
     dc.SaveChanges();
 }