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 virtual ActionResult EditProfile(EditProfile profile) { if (this.userProfileService.GetUserDefaultProfileId() != Context.User.Profile.ProfileItemId) { return this.View("InfoMessage", new InfoMessage(Errors.ProfileMismatch, InfoMessage.MessageType.Error)); } if (!this.userProfileService.ValidateProfile(profile, this.ModelState)) { profile.InterestTypes = this.userProfileService.GetInterests(); return this.View(profile); } this.userProfileService.SetProfile(Context.User.Profile, profile); return this.View("InfoMessage", new InfoMessage(Captions.EditProfileSuccess)); }
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 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, ["Name"] = model.FirstName, ["FullName"] = $"{model.FirstName} {model.LastName}", }; this.userProfileProvider.SetCustomProfile(userProfile, properties); }
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; }