public async Task<ActionResult> Edit() { TeacherAccountViewModel model; using (var userManager = UserManager) { var currentUserId = CurrentUserId; var currentUser = await userManager.FindByIdAsync(currentUserId); var currentTeacher = teacherRepository.GetTeacher(currentUser.Teacher.TeacherId); model = new TeacherAccountViewModel() { FullName = currentTeacher.FullName, //Part of account info AccountEmail = currentUser.Email, //Part of teacher info Email = currentTeacher.Email, Slug = currentTeacher.NameSlug, Degree = currentTeacher.Degree, Greetings = currentTeacher.Greetings, Intellect = currentTeacher.Intellect, Facebook = currentTeacher.Facebook, Vk = currentTeacher.Vk, Twitter = currentTeacher.Twitter, ScienceInterests = currentTeacher.ScienceInterests, Disciplines = currentTeacher.Disciplines, Projects = currentTeacher.Projects, Publications = currentTeacher.Publications, HasBlog = currentTeacher.Blog != null }; } return View("Edit",model); }
public async Task<ActionResult> Edit(TeacherAccountViewModel model) { using (var userManager = UserManager) { var currentUserId = CurrentUserId; var currentUser = await userManager.FindByIdAsync(currentUserId); var currentTeacher = teacherRepository.GetTeacher(currentUser.Teacher.TeacherId); if (string.IsNullOrWhiteSpace(model.Password)) { ModelState.AddModelError("PageError", "Password must be supplied"); } else { if (ModelState.IsValid && await CheckCurrentPasswordAsync(currentUserId, model.Password)) { if (!string.IsNullOrWhiteSpace(model.NewPassword)) { var result = await userManager.ChangePasswordAsync(currentUserId, model.Password, model.NewPassword); if (result.Succeeded) { //TODO: Messenger _logger.Trace($"{currentUser.UserName} succesfully changed password"); } else { foreach (var item in result.Errors) { ModelState.AddModelError("Password", item); } _logger.Trace($"{currentUser.UserName} failed password change"); } } //TODO: Messenger currentTeacher.Degree = model.Degree; currentTeacher.Email = model.Email; currentTeacher.Greetings = model.Greetings; currentTeacher.Intellect = model.Intellect; currentTeacher.Vk = model.Vk; currentTeacher.Facebook = model.Facebook; currentTeacher.Twitter = model.Twitter; currentTeacher.Disciplines = model.Disciplines; currentTeacher.Projects = model.Projects; currentTeacher.Publications = model.Publications; currentTeacher.ScienceInterests = model.ScienceInterests; teacherRepository.UpdateTeacher(currentTeacher); _logger.Trace($"Teacher {currentTeacher.FullName} updated profile"); } } return View("Edit",model); } }