public virtual EditProfile GetProfile(UserProfile userProfile) { var properties = this.userProfileProvider.GetCustomProperties(userProfile); var model = new EditProfile(); if (properties.ContainsKey(this.FirstName)) { model.FirstName = properties[this.FirstName]; } if (properties.ContainsKey(this.LastName)) { model.LastName = properties[this.LastName]; } if (properties.ContainsKey(this.PhoneNumber)) { model.PhoneNumber = properties[this.PhoneNumber]; } if (properties.ContainsKey(this.Interest)) { model.Interest = properties[this.Interest]; } model.InterestTypes = this.profileSettingsService.GetInterests(); return model; }
public void SetProfile(EditProfile editProfileModel) { if (this.contactProfileProvider.Contact == null) return; var personalInfo = this.contactProfileProvider.PersonalInfo; personalInfo.FirstName = editProfileModel.FirstName; personalInfo.Surname = editProfileModel.LastName; this.SetTag(InterestsTagName, editProfileModel.Interest ?? string.Empty); this.SetPreferredPhoneNumber(editProfileModel.PhoneNumber); this.SetPreferredEmail(Context.User.Profile.Email); this.contactProfileProvider.Flush(); }
public void ShouldSetContactProfile([Frozen] IContactProfileProvider contactProfileProvider, string key, IPhoneNumber phoneNumber, string firstName, string lastName, IContactPersonalInfo personalInfo, Sitecore.Analytics.Tracking.Contact contact) { contactProfileProvider.Contact.Returns(contact); var contactProfileService = new ContactProfileService(contactProfileProvider); contactProfileProvider.PersonalInfo.Returns(personalInfo); var profile = new EditProfile(); profile.FirstName = firstName; profile.LastName = lastName; profile.PhoneNumber = phoneNumber.Number; contactProfileService.SetProfile(profile); contactProfileProvider.PersonalInfo.FirstName.ShouldBeEquivalentTo(profile.FirstName); contactProfileProvider.PersonalInfo.Surname.ShouldBeEquivalentTo(profile.LastName); contactProfileProvider.PhoneNumbers.Entries[contactProfileProvider.PhoneNumbers.Preferred].Number.ShouldBeEquivalentTo(profile.PhoneNumber); }
public virtual void SetProfile(UserProfile userProfile, EditProfile model) { var properties = new Dictionary<string, string> { [this.FirstName] = model.FirstName, [this.LastName] = model.LastName, [this.PhoneNumber] = model.PhoneNumber, [this.Interest] = model.Interest, [nameof(userProfile.Name)] = model.FirstName, [nameof(userProfile.FullName)] = $"{model.FirstName} {model.LastName}".Trim() }; this.userProfileProvider.SetCustomProfile(userProfile, properties); }
public virtual ActionResult EditProfile(EditProfile profile) { if (this.userProfileService.GetUserDefaultProfileId() != Context.User.Profile.ProfileItemId) { return this.InfoMessage(InfoMessage.Error(Errors.ProfileMismatch)); } if (!this.userProfileService.ValidateProfile(profile, this.ModelState)) { profile.InterestTypes = this.userProfileService.GetInterests(); return this.View(profile); } this.userProfileService.SetProfile(Context.User.Profile, profile); if (this.contactProfileService != null) { this.contactProfileService.SetProfile(profile); } Session["EditProfileMessage"] = new InfoMessage(Captions.EditProfileSuccess); return this.Redirect(Request.RawUrl); }
public virtual ActionResult EditProfile(EditProfile profile) { if (this.userProfileService.GetUserDefaultProfileId() != Context.User.Profile.ProfileItemId) { return this.ProfileMismatchMessage; } if (!this.userProfileService.ValidateProfile(profile, this.ModelState)) { profile.InterestTypes = this.userProfileService.GetInterests(); return this.View(profile); } this.userProfileService.SetProfile(Context.User.Profile, profile); this.contactProfileService?.SetProfile(profile); this.Session["EditProfileMessage"] = new InfoMessage(DictionaryPhraseRepository.Current.Get("/Accounts/Edit Profile/Edit Profile Success", "Profile was successfully updated")); return this.Redirect(this.Request.RawUrl); }
public virtual bool ValidateProfile(EditProfile model, ModelStateDictionary modelState) { if (!this.profileSettingsService.GetInterests().Contains(model.Interest) && !string.IsNullOrEmpty(model.Interest)) { modelState.AddModelError(nameof(model.Interest), DictionaryPhraseRepository.Current.Get("/Accounts/Edit Profile/Interest Not Found", "Please select an interest from the list.")); } return modelState.IsValid; }
public void ValidateProfileShouldreturnValid(ModelStateDictionary modelState, [Frozen] IEnumerable<string> interests, IProfileSettingsService profileSettingsService, IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService) { var editProfile = new EditProfile() { Interest = interests.First() }; var result = userProfileService.ValidateProfile(editProfile, modelState); result.Should().BeTrue(); }
public void ValidateProfileShouldAddModelError(ModelStateDictionary modelState, [Frozen] IEnumerable<string> interests, IProfileSettingsService profileSettingsService, IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService) { var editProfile = new EditProfile() { Interest = "invalid interest" }; var result = userProfileService.ValidateProfile(editProfile, modelState); result.Should().BeFalse(); modelState.Keys.Should().Contain("Interest"); }
public virtual bool ValidateProfile(EditProfile model, ModelStateDictionary modelState) { if (!this.profileSettingsService.GetInterests().Contains(model.Interest) && !string.IsNullOrEmpty(model.Interest)) { modelState.AddModelError("Interest", Errors.WrongInterest); } return modelState.IsValid; }