public ActionResult Edit() { var studentId = User.Identity.GetUserId(); var student1 = db.Students.SingleOrDefault(x => x.Id == studentId); EditStudentProfileViewModel Profile = new EditStudentProfileViewModel(); Profile.Email = student1.Email; Profile.FirstName = student1.FirstName; //Profile.LastName = student1.LastName; return(View(Profile)); }
public ActionResult Edit(EditStudentProfileViewModel Profile) { var studentId = User.Identity.GetUserId(); var student1 = db.Students.SingleOrDefault(x => x.Id == studentId); student1.Email = Profile.Email; student1.FirstName = Profile.FirstName; student1.LastName = Profile.LastName; student1.Major = Profile.Major; db.Entry(student1).State = EntityState.Modified; db.SaveChanges(); return(View(Profile)); }
public ActionResult CSOEditStudentProfile(string id) { try { AppUser student = _db.Users .Include(u => u.Major) .FirstOrDefault(u => u.Id == id); EditStudentProfileViewModel cesvm = new EditStudentProfileViewModel(); cesvm.Email = student.Email; cesvm.FirstName = student.FirstName; cesvm.LastName = student.LastName; cesvm.GraduationDate = student.GraduationDate.ToString(); cesvm.Major = student.Major; cesvm.GPA = student.GPA.ToString(); if (student.PositionType == "FT") { cesvm.PositionType = Classification.FT; } if (student.PositionType == "I") { cesvm.PositionType = Classification.I; } //add the rest of the fields on evm from student ViewBag.AllMajors = GetAllMajors(student.Major.MajorID); //add evm in the () return(View(cesvm)); } catch { return(NotFound()); } }
public ActionResult EditStudentProfile() { AppUser student = _db.Users.Include(u => u.Major).FirstOrDefault(u => u.UserName == User.Identity.Name); EditStudentProfileViewModel esvm = new EditStudentProfileViewModel(); esvm.Email = student.Email; esvm.FirstName = student.FirstName; esvm.LastName = student.LastName; esvm.GraduationDate = student.GraduationDate.ToString(); esvm.Major = student.Major; esvm.GPA = student.GPA.ToString(); if (student.PositionType == "FT") { esvm.PositionType = Classification.FT; } if (student.PositionType == "I") { esvm.PositionType = Classification.I; } ViewBag.AllMajors = GetAllMajors(student.Major.MajorID); return(View(esvm)); }
public async Task <IActionResult> CSOEditStudentProfile(string id, EditStudentProfileViewModel model, int SelectedMajor, Classification SelectedPositionType) { Decimal newdecStudentGPA; Int32 newintGraduationDate; try { newdecStudentGPA = Convert.ToDecimal(model.GPA); } catch //this code will display when something is wrong { //Add a message for the viewbag ViewBag.Message5 = "GPA must be a valid decimal"; //Re-populate dropdown ViewBag.AllMajors = GetAllMajors(SelectedMajor); //Send user back to home page return(View(model)); } try { newintGraduationDate = Convert.ToInt32(model.GraduationDate); } catch //this code will display when something is wrong { //Add a message for the viewbag ViewBag.Message6 = "GraduationDate must be a valid number"; //Re-populate dropdown ViewBag.AllMajors = GetAllMajors(SelectedMajor); //Send user back to home page return(View(model)); } ModelState.Clear(); Major newMajor = _db.Majors.Find(SelectedMajor); /* * if (SelectedPositionType == Classification.FT) * { * model.PositionType = "FT"; * } * else * { * model.PositionType = "I"; * }*/ model.Major = newMajor; TryValidateModel(model); if (!ModelState.IsValid) { ViewBag.AllMajors = GetAllMajors(SelectedMajor); return(View(model)); } if (ModelState.IsValid) { AppUser CSOEditStudent = await _userManager.FindByIdAsync(id); CSOEditStudent.FirstName = model.FirstName; CSOEditStudent.LastName = model.LastName; CSOEditStudent.Email = model.Email; CSOEditStudent.Major = newMajor; CSOEditStudent.GraduationDate = newintGraduationDate; CSOEditStudent.PositionType = SelectedPositionType.ToString(); CSOEditStudent.GPA = newdecStudentGPA; IdentityResult editresult = await _userManager.UpdateAsync(CSOEditStudent); if (editresult.Succeeded) { AppUser userLoggedIn = await _userManager.FindByNameAsync(User.Identity.Name); await _signInManager.SignInAsync(userLoggedIn, isPersistent : false); return(RedirectToAction("Index", "StudentSearch")); } else { foreach (IdentityError error in editresult.Errors) { ModelState.AddModelError("", error.Description); } } } //re-populate the Viewbag in case there is an error ViewBag.AllMajors = GetAllMajors(SelectedMajor); return(View(model)); }