public ActionResult Details(int id) { IProfileService service = ProfileService.GetInstance<ProfileRepository>(); Profile profile = service.Get(id); if (profile == null || id == 0) { return RedirectToAction("Index", "Dashboard"); } ProfileViewModel model = new ProfileViewModel(profile); return View(model); }
public ActionResult Save(ProfileViewModel profileVM) { IProfileService profileService = ProfileService.GetInstance<ProfileRepository>(); if (!ModelState.IsValid) { TempData["ProfileModel"] = profileVM; TempData["Errors"] = ModelState.Values.SelectMany(v => v.Errors).ToList(); return RedirectToAction("Index", "Profile"); } Profile profile = GetProfile(); //UpdateOrCreateMemberSchool(profile, profileVM); profile.Name = profileVM.Name; profile.Country = profile.Country; profileVM.CurrentPassword = profileVM.CurrentPassword ?? ""; if (!string.IsNullOrEmpty(profileVM.CurrentPassword.Trim())) { string currentPasswordHash = HashSumUtil.GetHashSum(profileVM.CurrentPassword, HashSumType.SHA1); if (currentPasswordHash.Equals(profile.Password)) { if (profileVM.NewPassword.Equals(profileVM.ConfirmPassword) && !string.IsNullOrEmpty(profileVM.NewPassword)) { string newPasswordHash = HashSumUtil.GetHashSum(profileVM.NewPassword, HashSumType.SHA1); profile.Password = newPasswordHash; } else { ModelState.AddModelError("PasswordError", "Passwords doesn\'t match."); TempData["ProfileModel"] = profileVM; TempData["Errors"] = ModelState.Values.SelectMany(v => v.Errors).ToList(); RedirectToAction("Index", "Profile"); } } else { ModelState.AddModelError("PasswordError", "Current Password Invalid"); TempData["ProfileModel"] = profileVM; TempData["Errors"] = ModelState.Values.SelectMany(v => v.Errors).ToList(); RedirectToAction("Index", "Profile"); } } profileService.Update(profile); return RedirectToAction("Index", "Profile"); }
private ProfileViewModel GetProfileViewModel(Profile profile) { ProfileViewModel model = new ProfileViewModel(profile); return model; }