public ActionResult DeleteConfirmed(string id) { DrivingSchool_Instructors drivingSchool_Instructors = db.DrivingSchool_Instructors.Find(id); db.DrivingSchool_Instructors.Remove(drivingSchool_Instructors); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "InstructorsDrivingSchoolId,CreateDate,EditDate,InstructorId,DrivingSchoolId")] DrivingSchool_Instructors drivingSchool_Instructors) { if (ModelState.IsValid) { db.Entry(drivingSchool_Instructors).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DrivingSchoolId = new SelectList(db.DrivingSchools, "DrivingSchoolId", "Name", drivingSchool_Instructors.DrivingSchoolId); ViewBag.InstructorId = new SelectList(db.Instructors, "InstructorId", "Firstname", drivingSchool_Instructors.InstructorId); return(View(drivingSchool_Instructors)); }
// GET: DrivingSchool_Instructors/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DrivingSchool_Instructors drivingSchool_Instructors = db.DrivingSchool_Instructors.Find(id); if (drivingSchool_Instructors == null) { return(HttpNotFound()); } return(View(drivingSchool_Instructors)); }
public ActionResult Create([Bind(Include = "Firstname,Lastname,DOB,Gender,Driving_instructor_licence,Working_since,Email,PhoneNumber,UserName,About,Licences_held,Licences_training_for,Province,Cities_of_operation,Vehicles_used,DrivingSchoolsIds")] Instructor model, string DrivingSchoolsId, string PasswordHash) { // check if an instructor with the same firstname, lastname and dob already exists Instructor checkmodel = db.Instructors.SingleOrDefault(x => x.Firstname == model.Firstname && x.Lastname == model.Lastname && x.DOB == model.DOB); // check if the username entered already exists Instructor check_user_account = db.Instructors.SingleOrDefault(x => x.UserName == model.UserName); // if any duplication isn't found if (checkmodel == null || check_user_account == null) { if (ModelState.IsValid) { // Create a password has using the PasswordStorage external library model.PasswordHash = Drivo.ExternalLibraries.PasswordStorage.CreateHash(PasswordHash); // Add the instructor model db.Instructors.Add(model); db.SaveChanges(); // check if there is any Driving School the new instructor is affiliated to if (DrivingSchoolsId != null && DrivingSchoolsId != "none") { // Create a new Driving School Instructor relationship DrivingSchool_Instructors drivingschool_affiliation = new DrivingSchool_Instructors(); drivingschool_affiliation.InstructorId = model.InstructorId; drivingschool_affiliation.DrivingSchoolId = DrivingSchoolsId; model.DrivingSchool_Instructors.Add(drivingschool_affiliation); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } } else { // Give error based on the duplication found if (checkmodel == null) { ModelState.AddModelError("", "An instructor with the same name and date of birth" + (check_user_account == null ? " and username" : "") + " already exists. If you already have an account, please try to login."); } else { ModelState.AddModelError("", "An instructor with the same username already exists. Please, try again with a different username."); } } ViewBag.DrivingSchools = new MultiSelectList(db.DrivingSchools.ToList(), "DrivingSchoolId", "Name", model.DrivingSchool_Instructors.Select(x => x.DrivingSchoolId).ToArray()); return(View(model)); }
// GET: DrivingSchool_Instructors/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DrivingSchool_Instructors drivingSchool_Instructors = db.DrivingSchool_Instructors.Find(id); if (drivingSchool_Instructors == null) { return(HttpNotFound()); } ViewBag.DrivingSchoolId = new SelectList(db.DrivingSchools, "DrivingSchoolId", "Name", drivingSchool_Instructors.DrivingSchoolId); ViewBag.InstructorId = new SelectList(db.Instructors, "InstructorId", "Firstname", drivingSchool_Instructors.InstructorId); return(View(drivingSchool_Instructors)); }
public ActionResult AddInstructor([Bind(Include = "DrivingSchoolId")] DrivingSchool model, string[] InstructorIds) { if (InstructorIds != null) { foreach (string instructorId in InstructorIds) { DrivingSchool_Instructors drivingschool_instructors = new DrivingSchool_Instructors(); drivingschool_instructors.InstructorId = instructorId; drivingschool_instructors.DrivingSchoolId = model.DrivingSchoolId; db.DrivingSchool_Instructors.Add(drivingschool_instructors); } db.SaveChanges(); } return(RedirectToAction("Index")); }