I am working on a small application that serves as a “easy to use” way of adding new users. What I want to do is register a new user and assign it to an organisation, which is another table.
The whole thing currently looks like this:
The code (in .NET) currently looks like this:
BackendlessUser backendlessUser = new BackendlessUser();
backendlessUser.Email = emailInput.text;
backendlessUser.SetProperty("name", nameInput.text);
string name = organisationNames[organisationsDropdown.value];
BackendlessData.Organisations organisation = organisations.First(o => o.name == name);
BackendlessData.Organisations org = await Backendless.Data.Of<BackendlessData.Organisations>().FindByIdAsync(organisation.objectId, 2);
backendlessUser.SetProperty("organisation", org);
backendlessUser.Password = System.Web.Security.Membership.GeneratePassword(6, 3);
await Backendless.UserService.RegisterAsync(backendlessUser);
//int result = Backendless.Data.SetRelation("Users", backendlessUser, "organisation", new object[] { org });
Initially I tried to use the AddProperty of the user class, but that doesn’t seem to add the organisation. The last line was an attempt to add it through the SetRelation call. Although I do get a result back of 1 (which I think indicates that 1 relation value has been set) nothing gets added when I check the console and the organisation field remains empty.
What is the correct way of doing this?