public ActionResult Create(Participation participation) { if (ModelState.IsValid) { db.Participations.Add(participation); db.SaveChanges(); return RedirectToAction("Index"); } var viewModel = new ParticipationViewModel(GetActivityList(), GetStudentsList()) { Participation = participation }; return View(viewModel); }
public JsonResult New(NewParticipationsRequest request) { // var activity = db.Activities.Find(request.ActivityId); var participations = new List<Participation>(); foreach (var studentId in request.StudentIds) { // var student = db.Students.Find(studentId); var participation = new Participation() { ActivityId = request.ActivityId, Activity = db.Activities.Find(request.ActivityId), SubjectId = request.SubjectId, Subject = db.Subjects.Find(request.SubjectId), StudentId = studentId, Student = db.Students.Find(studentId), ParticipationDateTime = request.ParticipationDate, ExtraInfo = request.ExtraInfo }; db.Participations.Add(participation); participations.Add(participation); } db.SaveChanges(); return Json(participations); }
public ActionResult Edit(Participation participation) { if (ModelState.IsValid) { participation.Activity = db.Activities.Find(participation.ActivityId); participation.Subject = db.Subjects.Find(participation.Subject.SubjectId); participation.Student = db.Students.Find(participation.StudentId); db.Entry(participation).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } var viewModel = new ParticipationViewModel(GetActivityList(), GetStudentsList()) { Participation = participation }; return View(viewModel); }