Пример #1
0
        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);
        }
Пример #2
0
        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");
        }
Пример #3
0
 private ProfileViewModel GetProfileViewModel(Profile profile)
 {
     ProfileViewModel model = new ProfileViewModel(profile);
     return model;
 }