Пример #1
0
        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");
        }