public ActionResult NewTraining(Training training)
 {
     if (ModelState.IsValid)
     {
         using (var db = new ApplicationDbContext())
         {
             db.Trainings.Add(training);
             db.SaveChanges();
         }
     }
     return RedirectToAction("Index");
 }
        public ActionResult Details(Student student)
        {
            var db = new ApplicationDbContext();
            var trainingId = TempData["TrainingId"];
            var training = db.Trainings.First(t => t.Id == (int)trainingId);
            TempData["TrainingId"] = training.Id;
            if (ModelState.IsValid && Request.IsAjaxRequest())
            {
                training.Students.Add(student);
                db.SaveChanges();
                return Content("<li>" + student.FirstName + " " + student.LastName
                                + " " + student.University + " " + student.UniversityClass +
                                " cource</li>");
            }
            if (ModelState.IsValid)
            {
                training.Students.Add(student);
                db.SaveChanges();
                return RedirectToAction("Details", new { id = training.Id });
            }

            return (Request.IsAjaxRequest())? (ActionResult) Content(String.Empty) : RedirectToAction("Details", new { id = training.Id });
        }