//Get-Update public IActionResult Update(int? id) { AstronautTrainingVM AstronautTrainingVM = new AstronautTrainingVM() { AstronautTraining = new AstronautTraining(), AstronautDropDown = _db.Astronauts.Select(i => new SelectListItem { Text = i.Surname + " " + i.Name + ", " + i.Role.Name, Value = i.Id.ToString() }).ToList(), TrainingDropDown = _db.Trainings.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList() }; if (id == null || id == 0) { return NotFound(); } AstronautTrainingVM.AstronautTraining = _db.AstronautTrainings.Find(id); if (AstronautTrainingVM.AstronautTraining == null) { return NotFound(); } return View(AstronautTrainingVM); }
public IActionResult Create(AstronautTrainingVM obj) { if (ModelState.IsValid) { _db.AstronautTrainings.Add(obj.AstronautTraining); _db.SaveChanges(); return RedirectToAction("Index"); } return View(obj); }
//GET-Create public IActionResult Create() { AstronautTrainingVM astronautTrainingVM = new AstronautTrainingVM() { AstronautTraining = new AstronautTraining(), AstronautDropDown = _db.Astronauts.Select(i => new SelectListItem { Text = i.Surname + " " + i.Name + ", " + i.Role.Name, Value = i.Id.ToString() }).ToList(), TrainingDropDown = _db.Trainings.Where(x => x.IsValid).Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList() }; return View(astronautTrainingVM); }