Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

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 ExtensionsModulesModulesCreating User Relationship HelpCreating User Relationship Help
Previous
 
Next
New Post
10/3/2012 1:59 AM
 

Hi

I am trying to create a friend relationship programatically after an event but I am having a hard time with the API as I am still a novice to programming.

I think this what I need to use and it seems simple enough but I get 'invalid arguments' error and dont know why

IntiateUserRelationship(UserInfo, UserInfo, Relationship)

or

InitiateUserRelationship(InitiatingUser, TargetUser, Relationship)

to which I try
var initiator = base.UserId;
var target = 100;
var relationship = 7 //RelationshipId for 'friends' in my portal 

InitiateUserRelationship(initiator, target, relationship); 

this gives me the above mentioned error. Am I missing something?

Thanks for the help

Mark


 
New Post
10/3/2012 3:51 AM
 

With regard to the method -  InitiateUserRelationship(InitiatingUser, TargetUser, targetRelationship)

both TargetUser and InitiatingUser need to be of type UserInfo which is a properly instantiated user class.

you are trying to pass a TargetUser  with  a value of 100 this is an integer not a UserInfo class = you would need to load get the userinfo for userid 100 using:

UserInfo TargetUser = UserController.GetUserById(PortalId, 100 );

ALSO

The type of targetRelationship should be a property of type Relationship - you would need to get the relationship using:

Relationship targetRelationship = RelationshipController.Instance.GetRelationship(7);

Westa

 
New Post
10/3/2012 4:33 AM
 

Thanks. 

could you tell me why these work

UserInfo TargetUser = UserController.GetUserById(PortalId, 100 );
UserInfo TargetUser = UserController.GetUserById(PortalId, base.userId );

But this does not work

var friendId = Convert.ToInt32(hfFriendId); // data type is HiddenField
UserInfo TargetUser = UserController.GetUserById(PortalId, friendId );

in this case friendId is returning a Id but TargetUser remains null



 
New Post
10/3/2012 4:55 AM
 
Mark,

the method GetUserById requires an integer as the UserId.

var friendId

does not declare the friendId as an integer. So you should use either

int frientID = ...

or

...GetUserById(portalId, (int)friendId);

(not both, this would be too much - I would prefer the first version).

Best wishes
Michael

Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
10/3/2012 5:32 AM
 

Thanks, I have tried both approaches but it is still coming up null

UserInfo TargetUser = UserController.GetUserById(base.PortalId, (int)friendId);

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCreating User Relationship HelpCreating User Relationship Help


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.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out