public ActionResult Edit(Student student) { if (ModelState.IsValid) { context.Entry(student).State = EntityState.Modified; context.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
public ActionResult Create(Student student) { if (ModelState.IsValid) { context.Students.Add(student); context.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
public ActionResult SignUp(Student student, int sessionId, int locationId) { try { var studentRepository = new StudentRepository(); var session = _db.Sessions.SingleOrDefault(s => s.Id == sessionId); var location = _db.Locations.SingleOrDefault(s => s.Id == locationId); studentRepository.SignUp(student.Id, session.Id); } catch (Exception e) { var st = _db.Students.SingleOrDefault(s => s.Id == student.Id); ViewBag.LocationId = _db.Locations .ToList() .Select(inst => new SelectListItem { Text = inst.Name, Value = inst.Id.ToString() }); ViewBag.SessionId = _db.Sessions .ToList() .Select(inst => new SelectListItem { Text = inst.Name, Value = inst.Id.ToString() }); ModelState.AddModelError("", e.Message); return View(student); } return RedirectToAction("Index"); }