public ActionResult Create(ManagersCooperativesViewModels managerCoop) { if (ModelState.IsValid && validForm(managerCoop)) { // Si la coopérative existe, on ne l'ajoute pas en BD if (managerCoop.manager.IDCooperative == 0 || managerCoop.manager.IDCooperative == null) { db.Cooperative.Add(managerCoop.cooperative); db.SaveChanges(); managerCoop.manager.IDCooperative = managerCoop.cooperative.IDCooperative; } managerCoop.manager.ManagerPassword = UtilResources.EncryptPassword(Request.Form["password1"]); db.Manager.Add(managerCoop.manager); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } if (!ModelState.IsValid) { ModelState.AddModelError("", UtilResources.GetLabel("Tous les champs doivent contenir une valeur")); } return(View(managerCoop)); }
public ActionResult Create([Bind(Include = "IDStudent,FirstName,LastName,Email,PhoneNumber,StudentPassword")] Student student) { if (ModelState.IsValid && validForm()) { student.StudentPassword = UtilResources.EncryptPassword(Request.Form["password1"]); db.Student.Add(student); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } if (!ModelState.IsValid) { ModelState.AddModelError("", UtilResources.GetLabel("Tous les champs doivent contenir une valeur")); } return(View(student)); }