public ActionResult Edit([Bind(Include = "UserId,Email,Password,FirstName,LastName,mobile,role_type_id")] Administrator administrator) { StudentRegistrationsModel db = new StudentRegistrationsModel(); if (ModelState.IsValid) { db.Entry(administrator).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Admins"); } ViewBag.role_type_id = new SelectList(db.RoleTypes, "role_type_id", "role_name", administrator.role_type_id); return View(administrator); }
public ActionResult Edit(StudentRegistration theStudent) { StudentRegistrationsModel db = new StudentRegistrationsModel(); //if id == return //StudentRegistration theStudent = (StudentRegistration)db.StudentRegistrations.Where(m => m.Student_ID == id); ViewBag.id_courses = new SelectList(db.Courses, "id_courses", "course_name"); ViewBag.id_faculty = new SelectList(db.Faculties, "id_faculty", "faculty_name"); ViewBag.id_campus = new SelectList(db.Campus, "id_campus", "campus_name"); if (theStudent.Student_ID == null || theStudent.Student_ID.ToString().Trim() == String.Empty) { ModelState.AddModelError("Student_ID", "Can not be blank or empty"); //return View(StudentRegistration); } if (ModelState.IsValid) { //administrator.UserType = "Admin"; // db.Administrators.Add(administrator); db.Entry(theStudent).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(theStudent); }
public ActionResult ChangePassword(AdministratorLogin theAdmin) { StudentRegistrationsModel db = new StudentRegistrationsModel(); //passing back from session so no injection of userID or email can happen we also need to clear the model state and re-validate ModelState.Clear(); theAdmin.Email = this.AdminSession().Email; theAdmin.UserId = this.AdminSession().UserId; TryValidateModel(theAdmin); //ModelState.Clear(); //check password match if (theAdmin.Password != Request.Form["password_match"]) { //clear the viewbag password so they re-type ViewBag.password_match = String.Empty; ModelState.AddModelError("Password", "Passwords don't match"); } if (!ModelState.IsValid) { foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.Write(error); } } return View(theAdmin); } //grab the current admin session and update password //process the update AdministratorLogin thisUser = this.AdminSession(); var change = (from a in db.Administrators where a.UserId == thisUser.UserId select a).SingleOrDefault(); //rehash password change.Password = PasswordHashing.Encrypt(theAdmin.Password); //clean up from recovery if (Session["AdministratorRecovery"] != null) { Session.Remove("AdministratorRecovery"); //remove any recovery options that are set var recovery = (from b in db.Recoveries where b.UserId == change.UserId select b); foreach (var entry in recovery) db.Recoveries.Remove(entry); } db.Entry(change).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); }