johnw86
  • Posts: 10
  • Joined: 07/03/2012
Hello all,

I'm trying to update a users displayName via c#, from my Google search I keep coming across this post on stack overflow http://stackoverflow.com...ting-display-name-in-yaf  but at the bottom Jaban mentioned the latest code has a new method for doing this, does anyone know where this call is?


Thanks in advance

John
tha_watcha
  • Posts: 4036
  • Joined: 06/03/2010
Originally Posted by: johnw86

Hello all,

I'm trying to update a users displayName via c#, from my Google search I keep coming across this post on stack overflow http://stackoverflow.com...ting-display-name-in-yaf  but at the bottom Jaban mentioned the latest code has a new method for doing this, does anyone know where this call is?


Thanks in advance

John




Code snipped from the edit user profile page

// save remaining settings to the DB
            LegacyDb.user_save(
              this.currentUserID,
              this.PageContext.PageBoardID,
              null,
              displayName,
              null,
              this.TimeZones.SelectedValue.ToType<int>(),
              language,
              culture,
              theme,
              this.SingleSignOn.Checked,
              editor,
              this.UseMobileTheme.Checked,
              null,
              null,
              null,
              this.DSTUser.Checked,
              this.HideMe.Checked,
              null);

UserPostedImage
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Thanks for that I had seen that call I was hoping that there may be another call without the need to pull all those details out from the user to update the display name.

Thanks though.

John
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Hi,

Users details are being synced in the forum via a handler as I need to update the display name when it is updated in an external system, what is the best way to retrieve these properties for the LegacyDb.user_save as I can't see them on the MembershipUser or YafUserProfile


Thanks again,

John
tha_watcha
  • Posts: 4036
  • Joined: 06/03/2010
Originally Posted by: johnw86

Thanks for that I had seen that call I was hoping that there may be another call without the need to pull all those details out from the user to update the display name.

Thanks though.

John



You could add a new stored procedure that updates only the display name

CREATE procedure [{databaseOwner}].[{objectQualifier}user_update_displayname](
	@UserID				int,
	@DisplayName		nvarchar(255) = null)
AS
begin
	
		DisplayName = (CASE WHEN (@DisplayName is not null) THEN  @DisplayName ELSE DisplayName END)
end
GO


and the method

public static void user_update_displayname(
            [NotNull] object userID, 
            [NotNull] object displayName,)
        {
            using (var cmd = MsSqlDbAccess.GetCommand("user_update_displayname"))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("UserID", userID);
                cmd.Parameters.AddWithValue("DisplayName", displayName);
                MsSqlDbAccess.Current.ExecuteNonQuery(cmd);
            }
        }

UserPostedImage
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Yeah that was going to be my next move if there wasn't a simpler way of doing it. I was just trying my best to leave the source code/db alone for upgrades etc.

Thanks

John
tha_watcha
  • Posts: 4036
  • Joined: 06/03/2010
Originally Posted by: johnw86

Yeah that was going to be my next move if there wasn't a simpler way of doing it. I was just trying my best to leave the source code/db alone for upgrades etc.

Thanks

John



No i think it is the only way to do it. and you dont have to modify yaf itself,

- you could put the user_update_displayname method in your own code
- you can add custom procedures via the yaf installer without editing the procedures.sql. Simply add a new file in the Install folder called "custom.sql" where you can put all custom sql stuff.

UserPostedImage
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Perfect that's exactly what I will do.


John
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Just another quick question on this as I'm creating the users programatically and setting their display name what is the best way to get the userId to do the display name update. I have tried:

int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey);

But this seems to return 0, any other methods for retrieving the userId.


Thanks

John
bbobb
  • Posts: 1558
  • Joined: 21/10/2008
If you pass a correct providerUserKey it should not return 0, it seems you have an incorrect logic.
You don't need create users programmaticaly as they are put in YAF users table after their first visit.
The DisplayName = UserName in the beginning. So you can simply check if they are the same in your YAF control and if not - trigger user_save things.
johnw86
  • Posts: 10
  • Joined: 07/03/2012
Hi,

Im working on a custom AD membership and single sign on provider so I'm validating users against these two providers and if it's their first visit to the site I'm creating them as a user programmatically otherwise finding their account based on the username and logging them in.

To create the user im using:

YAF.Providers.Profile.DB profile = new YAF.Providers.Profile.DB();
var user = provider.CreateUser(params);

But then when I call int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); that is returning 0. Is there any other way I can get the userID out or is it a case of that logic above is incorrect?


Cheers,

John

bbobb
  • Posts: 1558
  • Joined: 21/10/2008
Oh, you'll have multiple pitfalls with AD. I can help with open source code only in difficult cases like this.
johnw86
  • Posts: 10
  • Joined: 07/03/2012
No problem, Im not actually using the AD membership I'm just authenticating users against that then logging them into a yaf account which has been associated with the AD user so still using YAF mem provider.

Found another method I needed to call after creating the user which seems to give me the newly created userID

int? userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID);

John
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved