public ActionResult Edit(CareerModel model) { if (ModelState.IsValid) { // update the career object var career = (from c in Context.sh_careers where c.CareerID == model.CareerID select c).First(); career.AverageSalary = model.AverageSalary; career.Demand = model.Demand; career.DisplayOrder = model.DisplayOrder; career.Level1Instructions = model.Level1Instructions; career.Level2Instructions = model.Level2Instructions; career.Level3Instructions = model.Level3Instructions; career.Level4Instructions = model.Level4Instructions; career.Level5Instructions = model.Level5Instructions; career.Description = model.Description; career.Name = model.Name; // clear old associations of certifications and add new ones. Context.sh_career_certifications.DeleteAllOnSubmit(career.sh_career_certifications); Context.SubmitChanges(); // create the associated certifications foreach (var id in model.SelectedCerts) { sh_career_certification assoc = new sh_career_certification() { CareerID = career.CareerID, CertificationID = id }; Context.sh_career_certifications.InsertOnSubmit(assoc); } // save to the database again Context.SubmitChanges(); return RedirectToAction("Index"); } return View(model); }
private void detach_sh_career_certifications(sh_career_certification entity) { this.SendPropertyChanging(); entity.sh_career = null; }
partial void Deletesh_career_certification(sh_career_certification instance);
partial void Updatesh_career_certification(sh_career_certification instance);
partial void Insertsh_career_certification(sh_career_certification instance);
private void attach_sh_career_certifications(sh_career_certification entity) { this.SendPropertyChanging(); entity.sh_certification = this; }
public ActionResult New(CareerModel model) { if (ModelState.IsValid) { var career = new sh_career() { AverageSalary = model.AverageSalary, Demand = model.Demand, DisplayOrder = model.DisplayOrder, Level1Instructions = model.Level1Instructions, Level2Instructions = model.Level2Instructions, Level3Instructions = model.Level3Instructions, Level4Instructions = model.Level4Instructions, Level5Instructions = model.Level5Instructions, Description = model.Description, Name = model.Name }; // create the career Context.sh_careers.InsertOnSubmit(career); // save to the database Context.SubmitChanges(); // create the associated certifications if (model.SelectedCerts != null) { foreach (var id in model.SelectedCerts) { sh_career_certification assoc = new sh_career_certification() { CareerID = career.CareerID, CertificationID = id }; Context.sh_career_certifications.InsertOnSubmit(assoc); } } // save to the database again Context.SubmitChanges(); return RedirectToAction("Edit", new { id = career.CareerID }); } return View(getModel()); }