Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Create user in the same organisation as current user.

Vote:
 

Hello,

I want to do the following scenario. I am logged in QuickSilver as user with a specific role, let's say "UserAdmin" and I want to create a user myself that will be part of the same organisation as I am, i.e. using the same form as for registering a normal user.
I am not sure how to get the organisation the current user belongs - I think I need to relate user to contacts of organisation. The documentation I have found here http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/9/Customers/Customers/ I think is outdated as those functions are now obsolete and obviously not covering everything. For instance the right way to get all the organisations now is using 
var organizations = CustomerContext.Current.GetOrganizations();
Submit
Any ideas how to do this right?

[Pasting files is not allowed]

#142165
Dec 03, 2015 9:48
Vote:
 

Hi,

CustomerContact has a property named ContactOrganization, or you can get the OrgarnizationId by CustomerContact.OwnerId (make sure to check if those are null)

Regards.

/Q

#142186
Dec 04, 2015 8:56
Vote:
 

Hello,

Thanks for your reply. I managed to solve this and this is how I did it. I got really surprised that I had to use something awkward like GetContactByUserId("String:" + user.Email) ...

//Get current user as contact and get contacts organisation id
var customerContact = CustomerContext.Current.CurrentContact;
var organizationId = customerContact.ContactOrganization.PrimaryKeyId;

//Get the created user as contact and set the ownerid which is the organisations id the same as the current user
var newCustomerContact = CustomerContext.Current.GetContactByUserId("String:" + user.Email);
if (newCustomerContact != null)
{
    newCustomerContact.OwnerId = organizationId;
    newCustomerContact.SaveChanges();
}

#142394
Dec 10, 2015 13:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.