Hi,
I have just taken over a project that has been running in 4.0 for some time and recently upgraded to 4.1.
After the 4.1 update the following code is no longer working:
customer.CustomerRoles.Add(this.RegisteredCustomerRole);
It does not generate any error. It just does not add the role to the customer.
I have replaced that code with:
CustomerRole registeredRole = this._customerService.GetCustomerRoleBySystemName("Registered");
CustomerCustomerRoleMapping customerCustomerRoleMapping = new CustomerCustomerRoleMapping();
customerCustomerRoleMapping.CustomerId = customer.Id;
customerCustomerRoleMapping.CustomerRoleId = registeredRole.Id;
customer.CustomerCustomerRoleMappings.Add(customerCustomerRoleMapping);
The new code works but I wonder why the old does not.
Is my new implementation "correct" or is there a "more correct" way to do it?
BTW, the code is used to create a customer account from a JSON file including adding the customer to the "Registered" role.
Any tips/comments are very welcome ;-)