public ProfileViewModel(INavigationService navigator, string navigationPath) { #region Navigation NavigationPath = navigationPath; _navigator = navigator; NavigateBack = new Command(() => { _navigator.NavigateBack(); }); UpdateCommand = new Command(async() => { if (!await Update()) { await _navigator.DisplayAlert("Alert", ErrorMessage, "OK"); } }); #endregion _user = new UserViewModel().User; ProfileInformation = new ProfileInformation { Username = _user.Username, Email = _user.Email, FirstName = _user.FirstName, LastName = _user.LastName, Address = _user.Address, City = _user.City, Country = _user.Country, ZipCode = _user.ZipCode }; }
/// <summary> /// Copies values from signed profile information to properties of this instance of the identity. /// </summary> /// <param name="SignedProfile">Signed information about the profile.</param> /// <param name="HostingServerId">In case of NeighborhIdentity, this is set to network identifier of the hosting server.</param> public void CopyFromSignedProfileInformation(SignedProfileInformation SignedProfile, byte[] HostingServerId) { if (HostingServerId == null) { HostingServerId = new byte[0]; } ProfileInformation profile = SignedProfile.Profile; byte[] pubKey = profile.PublicKey.ToByteArray(); byte[] identityId = Crypto.Sha256(pubKey); GpsLocation location = new GpsLocation(profile.Latitude, profile.Longitude); this.IdentityId = identityId; this.HostingServerId = HostingServerId; this.PublicKey = pubKey; this.Version = profile.Version.ToByteArray(); this.Name = profile.Name; this.Type = profile.Type; this.InitialLocationLatitude = location.Latitude; this.InitialLocationLongitude = location.Longitude; this.ExtraData = profile.ExtraData; this.ProfileImage = profile.ProfileImageHash.Length != 0 ? profile.ProfileImageHash.ToByteArray() : null; this.ThumbnailImage = profile.ThumbnailImageHash.Length != 0 ? profile.ThumbnailImageHash.ToByteArray() : null; this.Signature = SignedProfile.Signature.ToByteArray(); }
public bool BTSMember_InsertMemberId(ProfileInformation profile, string Id) { var p = new DynamicParameters(); p.Add("MemberId", Id); return(_dbConnection.Connection.Execute("BTSMember_InsertMemberId", p, commandType: CommandType.StoredProcedure) > 0); }
public void DeleteProfileInfo(int id) { var profile = new ProfileInformation() { UserId = id }; context.ProfileInformations.Attach(profile); context.ProfileInformations.Remove(profile); context.SaveChanges(); }
public ProfileInformation GetProfileInformation(string username) { var profileInformation = new ProfileInformation { AverageVote = _userRepository.AverageVote(username), AverageScore = _userRepository.GetAverageScore(username), NumberOfPhotosUploaded = _userRepository.NumberOfPhotosUploaded(username), NumberOfTimesVoted = _userRepository.NumberOfTimesVoted(username) }; return(profileInformation); }
public ActionResult AspNetUser_Update(ApplicationUser user, ProfileInformation profile) { if (ModelState.IsValid) { if (_businessTechSolutionsRepository.AspNetUser_Update(user)) { var Id = user.Id; _businessTechSolutionsRepository.BTSMember_InsertMemberId(profile, Id); return(RedirectToAction("Index", "AdminPage")); } } return(View()); }
public ActionResult InsertProfileInformation(ProfileInformation profile, string Id) { var id = User.Identity.GetUserId(); if (ModelState.IsValid) { if (_businessTechSolutionsRepository.BTSMember_UpdateProfileInformation(profile, id)) { return(RedirectToAction("Index", "Member")); } return(View()); } return(View()); }
public bool BTSMember_InsertProfileInformation(ProfileInformation profile, string Id) { var p = new DynamicParameters(); p.Add("FirstName", profile.FirstName); p.Add("LastName", profile.LastName); p.Add("MemberId", Id); p.Add("Major", profile.Major); p.Add("Status", profile.Status); profile.JoinDate = DateTime.Now; p.Add("JoinDate", profile.JoinDate); p.Add("GraduationDate", profile.GraduationDate); return(_dbConnection.Connection.Execute("BTSMember_InsertProfileInformation", p, commandType: CommandType.StoredProcedure) > 0); }
public void AddProfileInfo(RegisterViewModel register) { ProfileInformation dbprofiles = new ProfileInformation { FirstName = register.FirstName, LastName = register.LastName, Email = register.Email, Username = register.Username, UserId = register.UserId, Password = register.Password, InstagramConnect = register.InstagramConnect, TwitterConnect = register.TwitterConnect }; context.ProfileInformations.Add(dbprofiles); context.SaveChanges(); }
public JsonResult GetPersonalInfo() { ProfileInformation PI = ProfileInformation.PI(); var viewModel = new ProfileInformationViewModel() { FirstName = PI.FirstName, LastName = PI.LastName, Bio = PI.Bio, PreviousOccupation = PI.PreviousOccupation, MaritalStatus = PI.MaritalStatus, Location = PI.Location, Education = PI.Education, CurrentOccupation = PI.CurrentOccupation, Email = PI.Email, DoB = PI.DateOfBirth }; return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
public void AddProfileInfo(RegisterViewModel register) { ProfileInformation dbprofiles = new ProfileInformation { FirstName = register.FirstName, LastName = register.LastName, Email = register.Email, Username = register.Username, UserId = register.UserId, Password = register.Password, InstagramConnect = register.InstagramConnect, TwitterConnect = register.TwitterConnect, Birthdate = register.BirthDate, Gender = register.GenderType.ToString() }; context.ProfileInformations.Attach(dbprofiles); context.ProfileInformations.Add(dbprofiles); context.SaveChanges(); }
public ActionResult Index() { ProfileInformation PI = ProfileInformation.PI(); var dateofbirth = Convert.ToDateTime(PI.DateOfBirth); string date = ""; Date(ref date, dateofbirth); var viewModel = new ProfileInformationViewModel() { FirstName = PI.FirstName, LastName = PI.LastName, Bio = PI.Bio, PreviousOccupation = PI.PreviousOccupation, MaritalStatus = PI.MaritalStatus, Location = PI.Location, Education = PI.Education, CurrentOccupation = PI.CurrentOccupation, Email = PI.Email, DoB = date }; return(View(viewModel)); }
public ActionResult Index(string FirstName, string LastName, string Email, string MaritalStatus, string CurrentOccupation, string PrevOccupation, string Education, DateTime dateofbirth, string bio, string country, string city) { string date = ""; Date(ref date, dateofbirth); ProfileInformation PI = ProfileInformation.PI(); var viewModel = new ProfileInformationViewModel() { Bio = bio, Email = Email, MaritalStatus = MaritalStatus, CurrentOccupation = CurrentOccupation, Education = Education, FirstName = FirstName, LastName = LastName, Location = country + " " + city, PreviousOccupation = PrevOccupation, DoB = date }; return(View(viewModel)); }
/// <summary> /// Checks whether a profile information is valid. /// </summary> /// <param name="Profile">Profile information to check.</param> /// <param name="IdentityPublicKey">Public key of the profile's identity.</param> /// <param name="MessageBuilder">Client's network message builder.</param> /// <param name="RequestMessage">Full request message from client.</param> /// <param name="ErrorPrefix">Prefix to add to the validation error details.</param> /// <param name="ErrorResponse">If the function fails, this is filled with error response message that is ready to be sent to the client.</param> /// <returns>true if the signed profile information is valid, false otherwise.</returns> public static bool ValidateProfileInformation(ProfileInformation Profile, byte[] IdentityPublicKey, PsMessageBuilder MessageBuilder, PsProtocolMessage RequestMessage, string ErrorPrefix, out PsProtocolMessage ErrorResponse) { log.Trace("()"); bool res = false; ErrorResponse = null; string details = null; if (Profile == null) { Profile = new ProfileInformation(); } SemVer version = new SemVer(Profile.Version); // Currently only supported version is 1.0.0. if (!version.Equals(SemVer.V100)) { log.Debug("Unsupported version '{0}'.", version); details = "version"; } if (details == null) { byte[] pubKey = Profile.PublicKey.ToByteArray(); bool pubKeyValid = (0 < pubKey.Length) && (pubKey.Length <= ProtocolHelper.MaxPublicKeyLengthBytes) && ByteArrayComparer.Equals(IdentityPublicKey, pubKey); if (!pubKeyValid) { log.Debug("Invalid public key '{0}' does not match identity public key '{1}'.", pubKey.ToHex(), IdentityPublicKey.ToHex()); details = "publicKey"; } } if (details == null) { int typeSize = Encoding.UTF8.GetByteCount(Profile.Type); bool typeValid = (0 < typeSize) && (typeSize <= IdentityBase.MaxProfileTypeLengthBytes); if (!typeValid) { log.Debug("Invalid type size in bytes {0}.", typeSize); details = "type"; } } if (details == null) { int nameSize = Encoding.UTF8.GetByteCount(Profile.Name); bool nameValid = (0 < nameSize) && (nameSize <= IdentityBase.MaxProfileNameLengthBytes); if (!nameValid) { log.Debug("Invalid name size in bytes {0}.", nameSize); details = "name"; } } if (details == null) { GpsLocation locLat = new GpsLocation(Profile.Latitude, 0); if (!locLat.IsValid()) { log.Debug("Invalid latitude {0}.", Profile.Latitude); details = "latitude"; } } if (details == null) { GpsLocation locLon = new GpsLocation(0, Profile.Longitude); if (!locLon.IsValid()) { log.Debug("Invalid longitude {0}.", Profile.Longitude); details = "longitude"; } } if (details == null) { int extraDataSize = Encoding.UTF8.GetByteCount(Profile.ExtraData); bool extraDataValid = extraDataSize <= IdentityBase.MaxProfileExtraDataLengthBytes; if (!extraDataValid) { log.Debug("Invalid extraData size in bytes {0}.", extraDataSize); details = "extraData"; } } if (details == null) { bool profileImageHashValid = (Profile.ProfileImageHash.Length == 0) || (Profile.ProfileImageHash.Length == ProtocolHelper.HashLengthBytes); if (!profileImageHashValid) { log.Debug("Invalid profile image hash size {0} bytes.", Profile.ProfileImageHash.Length); details = "profileImageHash"; } } if (details == null) { bool thumbnailImageHashValid = (Profile.ThumbnailImageHash.Length == 0) || (Profile.ThumbnailImageHash.Length == ProtocolHelper.HashLengthBytes); if (!thumbnailImageHashValid) { log.Debug("Invalid thumbnail image hash size {0} bytes.", Profile.ThumbnailImageHash.Length); details = "thumbnailImageHash"; } } if (details == null) { res = true; } else { ErrorResponse = MessageBuilder.CreateErrorInvalidValueResponse(RequestMessage, ErrorPrefix + details); } log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Updates identity profile and creates neighborhood action to propagate the change unless the client did not want the propagation. /// </summary> /// <param name="IdentityId">Network identifier of the identity to update.</param> /// <param name="SignedProfile">Signed profile information with updated values.</param> /// <param name="ProfileImageChanged">True if profile image is about to change.</param> /// <param name="ThumbnailImageChanged">True if thumbnail image is about to change.</param> /// <param name="NoPropagation">True if the client does not want this change of profile to be propagated to the neighborhood.</param> /// <param name="IdentityNotFound">If the function fails because the identity is not found, this referenced value is set to true.</param> /// <param name="ImagesToDelete">If the function succeeds and the profile images are altered, old image files has to be deleted, in which case their hashes /// are returned in this list, which has to be initialized by the caller.</param> /// <returns>true if the function succeeds, false otherwise.</returns> public async Task <bool> UpdateProfileAndPropagateAsync(byte[] IdentityId, SignedProfileInformation SignedProfile, bool ProfileImageChanged, bool ThumbnailImageChanged, bool NoPropagation, StrongBox <bool> IdentityNotFound, List <byte[]> ImagesToDelete) { log.Trace("()"); bool res = false; bool signalNeighborhoodAction = false; bool success = false; List <byte[]> imagesToDelete = new List <byte[]>(); ProfileInformation profile = SignedProfile.Profile; DatabaseLock[] lockObjects = new DatabaseLock[] { UnitOfWork.HostedIdentityLock, UnitOfWork.FollowerLock, UnitOfWork.NeighborhoodActionLock }; using (IDbContextTransaction transaction = await unitOfWork.BeginTransactionWithLockAsync(lockObjects)) { try { HostedIdentity identity = (await GetAsync(i => (i.IdentityId == IdentityId) && (i.Cancelled == false))).FirstOrDefault(); if (identity != null) { bool isProfileInitialization = !identity.Initialized; identity.Initialized = true; identity.Version = profile.Version.ToByteArray(); identity.Name = profile.Name; GpsLocation location = new GpsLocation(profile.Latitude, profile.Longitude); identity.SetInitialLocation(location); identity.ExtraData = profile.ExtraData; identity.Signature = SignedProfile.Signature.ToByteArray(); if (ProfileImageChanged) { if (identity.ProfileImage != null) { imagesToDelete.Add(identity.ProfileImage); } identity.ProfileImage = profile.ProfileImageHash.Length != 0 ? profile.ProfileImageHash.ToByteArray() : null; } if (ThumbnailImageChanged) { if (identity.ThumbnailImage != null) { imagesToDelete.Add(identity.ThumbnailImage); } identity.ThumbnailImage = profile.ThumbnailImageHash.Length != 0 ? profile.ThumbnailImageHash.ToByteArray() : null; } Update(identity); if (!NoPropagation) { // The profile change has to be propagated to all our followers // we create database actions that will be processed by dedicated thread. NeighborhoodActionType actionType = isProfileInitialization ? NeighborhoodActionType.AddProfile : NeighborhoodActionType.ChangeProfile; string extraInfo = identity.PublicKey.ToHex(); signalNeighborhoodAction = await unitOfWork.NeighborhoodActionRepository.AddIdentityProfileFollowerActionsAsync(actionType, identity.IdentityId, extraInfo); } await unitOfWork.SaveThrowAsync(); transaction.Commit(); success = true; } else { IdentityNotFound.Value = true; } } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } if (!success) { log.Warn("Rolling back transaction."); unitOfWork.SafeTransactionRollback(transaction); } unitOfWork.ReleaseLock(lockObjects); } if (success) { // Only when the function succeeds the old images can be deleted. ImagesToDelete.AddRange(imagesToDelete); // Send signal to neighborhood action processor to process the new series of actions. if (signalNeighborhoodAction) { Network.NeighborhoodActionProcessor neighborhoodActionProcessor = (Network.NeighborhoodActionProcessor)Base.ComponentDictionary[Network.NeighborhoodActionProcessor.ComponentName]; neighborhoodActionProcessor.Signal(); } res = true; } log.Trace("(-):{0}", res); return(res); }