Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsOther Extension...Other Extension...DNN 7 Custom User Profile Properties Not Updated ProgramaticallyDNN 7 Custom User Profile Properties Not Updated Programatically
Previous
 
Next
New Post
5/17/2013 4:02 PM
 

Can anyone see why the following code does not update user profile properties?

public static void UpdateDNNUserProfileProperties(int PortalId, int UserID, IDictionary props) { DotNetNuke.Entities.Users.UserInfo CurUser = DotNetNuke.Entities.Users.UserController.GetUser(PortalId, UserID, false); 
string value = ""; 
foreach (var item in props) { 
   if (props.Contains("DateOfBirth")) { 
   value = Convert.ToString(props["DateOfBirth"]); CurUser.Profile.SetProfileProperty("DateOfBirth", value); 
      if (props.Contains("AgeVerified")) {
      value = Convert.ToString(props["AgeVerified"]); 
      CurUser.Profile.SetProfileProperty("AgeVerified", value); 

   if (props.Contains("ProjectTermsAgreed")) { 
      value = Convert.ToString(props["ProjectTermsAgreed"]); 
      CurUser.Profile.SetProfileProperty("ProjectTermsAgreed", value); 

DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, CurUser); 
}

 

More info: User already exists; profile properties added later.
I stepped through it and each property has a value.
DNN 7.04
Thanks to whoever can help.

 

 
New Post
5/19/2013 6:34 PM
 
When getting the current user, you need to set the Hydrated flag to "True" rather than "false"

-Mitchel Sellers
Microsoft C# MVP, MCITP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
5/20/2013 11:12 AM
 

OK, Visual Studio 2012 is reporting that 

DotNetNuke.Entities.Users.UserController.GetUser(PortalId, UserID, false); is deprecated and the hydrated flag is not used, so I didn't think it mattered.

I did discover an issue with the stored procedure that updates the User Profile table:
(DNN 7.x ONLY from what I can tell)

Stored Procedure: UpdateUserProfileProperty

Below is the  CHANGED version.
(In the ORIGNAL version, notice the line: 
IF @ProfileID IS NULL
  -- this will return false if -1 is passed in for ProfileID and no record exists, hence the update fails)

It has to be changed to:  IF ISNULL(@ProfileID,0) >0 (SEE BELOW)


ALTER PROC [dbo].[UpdateUserProfileProperty] 

@ProfileID int,
@UserID int,
@PropertyDefinitionID int,
@PropertyValue ntext,
@Visibility int,
@ExtendedVisibility varchar(400),
@LastUpdatedDate datetime

AS
IF @ProfileID IS NOT NULL
-- Try the UserID/PropertyDefinitionID to see if the Profile property exists
SELECT @ProfileID = ProfileID
FROM   dbo.UserProfile
WHERE  UserID = @UserID AND PropertyDefinitionID = @PropertyDefinitionID
 
IF ISNULL(@ProfileID,0) >0
-- Update Property
BEGIN
UPDATE dbo.UserProfile
SET PropertyValue = case when (DATALENGTH(@PropertyValue) > 7500) then NULL else @PropertyValue end,
PropertyText = case when (DATALENGTH(@PropertyValue) > 7500) then @PropertyValue else NULL end,
Visibility = @Visibility,
ExtendedVisibility = @ExtendedVisibility,
LastUpdatedDate = @LastUpdatedDate
WHERE  ProfileID = @ProfileID
SELECT @ProfileID
END
ELSE
-- Insert New Property
BEGIN
INSERT INTO dbo.UserProfile (
UserID,
PropertyDefinitionID,
PropertyValue,
PropertyText,
Visibility,
ExtendedVisibility,
LastUpdatedDate
 )
VALUES (
@UserID,
@PropertyDefinitionID,
case when (DATALENGTH(@PropertyValue) > 7500) then NULL else @PropertyValue end,
case when (DATALENGTH(@PropertyValue) > 7500) then @PropertyValue else NULL end,
@Visibility,
@ExtendedVisibility,
@LastUpdatedDate
 )

SELECT SCOPE_IDENTITY()
END

 

 
New Post
5/20/2013 12:36 PM
 
Mitchel Sellers wrote:
When getting the current user, you need to set the Hydrated flag to "True" rather than "false"

I think there's something else wrong wtih profile properties implementation in DNN 7 (besides the UpdateProfileProperty stored procedure mentioned in this post).  

None of the custom profile properties are being returned by the UserInfo Profile ProfileProperties object, only the 20 properties added by default.

For example, in the Database, UserProfile table, "AgeVerified" is there as ProfileID 54 with ProfilePropertyDefinition 44.

However the following code doesn't return it (CurUser.Profile.ProfileProperties["AgeVerified"] is null):

DotNetNuke.Entities.Users.UserInfo CurUser = DotNetNuke.Entities.Users.UserController.GetUserByName(PortalId, (string)_currentUser.UserName); if (CurUser.Profile.ProfileProperties["AgeVerified"] != null) { this.chkAgeVerification.Checked = Convert.ToBoolean(CurUser.Profile.ProfileProperties["AgeVerified"]); }

What do I use in DNN 7 to return all the profile properties including the custom ones?

 

 

 

 
New Post
11/1/2013 6:59 AM
 
Good morning

I am trying to update custom properties, and I don't know what I'm doing wrong...this is my code:

UserInfo currentUSer = UserController.GetUserById(UserInfo.PortalID, UserInfo.UserID);
currentUSer.Profile.SetProfileProperty("SiteAddress", txtSiteAddress.Text);
currentUSer.Profile.SetProfileProperty("SiteDeliveryAddress", txtSiteDeliveryAddress.Text);
ProfileController.UpdateUserProfile(currentUSer, currentUSer.Profile.ProfileProperties);
UserController.UpdateUser(currentUSer.PortalID, currentUSer);

I have tried as well:

UserInfo.Profile.SetProfileProperty("SiteAddress", txtSiteAddress.Text);
UserInfo.Profile.SetProfileProperty("SiteDeliveryAddress", txtSiteDeliveryAddress.Text);
ProfileController.UpdateUserProfile(UserInfo, UserInfo.Profile.ProfileProperties);
UserController.UpdateUser(UserInfo.PortalID, UserInfo);

I know the properties are available, as I am pre-populating text boxes as below without any issues:

txtSiteAddress.Text = UserInfo.Profile.GetPropertyValue("SiteAddress");
txtSiteDeliveryAddress.Text = UserInfo.Profile.GetPropertyValue("SiteDeliveryAddress");

I have no idea what may be wrong. I've thought that maybe the IsDirty flag is not being set to true, but I have no idea how to change that and I cannot find any help online. 

Hope you guys can help!
Cheers
C
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsOther Extension...Other Extension...DNN 7 Custom User Profile Properties Not Updated ProgramaticallyDNN 7 Custom User Profile Properties Not Updated Programatically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  


Copyright 2017 by DNN Corp Terms of Use Privacy
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out