1: /// <summary>
2: /// Enables self-service for the specified contactId
3: /// </summary>
4: /// <param name="contact">Contact object</param>
5: /// <returns>password for the newly created Self-Service user.</returns>
6: public string EnableSelfService(Contact contact)
7: {
8: string email, firstName, lastName, contactId;
9: //Verify that we are already authenticated, if not
10: //call the login function to do so
11: if (!loggedIn)
12: {
13: if (!Login())
14: return null;
15: }
16: email = contact.Email;
17: firstName = contact.FirstName;
18: lastName = contact.LastName;
19:
20: // I needed to make some changes to the contact first. So update the contact...
21: contactId = contact.Id;
22: contact = new Contact();
23: contact.Id = contactId;
24: contact.Enable_MySequenom__c = true;
25: contact.Enable_MySequenom__cSpecified = true;
26: contact.MySequenom_Enabled_On__c = DateTime.Now;
27: contact.MySequenom_Enabled_On__cSpecified = true;
28:
29: // then save the contact.
30: try
31: {
32: SaveResult[] srContact = binding.update(new sObject[] { contact });
33: }
34: catch (Exception e)
35: {
36: throw new ApplicationException("Unable to update contact record for contactid: " + contactId + Environment.NewLine + e.ToString());
37: }
38:
39: // open the contact back up.
40: contact = GetContact(contactId);
41:
42: // check to see if a self-service user already exists for this contact.
43: string ssuId = GetExistingSelfServiceUserId(contact.Email);
44:
45: // Self-Service user already exists, just reset password.
46: if (ssuId != null){
47: return ResetPassword(ssuId);
48: }
49:
50: // Create the new self-service user.
51: SelfServiceUser ssu = new SelfServiceUser();
52: ssu.ContactId = contactId;
53: ssu.Email = email;
54: ssu.FirstName = firstName;
55: ssu.LastName = lastName;
56: ssu.Username = contact.Email;
57: ssu.IsActive = true;
58: ssu.IsActiveSpecified = true;
59: ssu.LanguageLocaleKey = "en_US";
60: ssu.LocaleSidKey = "en_US";
61: ssu.TimeZoneSidKey = "America/Los_Angeles";
62:
63: // Invoke the create call, passing in the SelfServiceUser properties
64: // and saving the results in a SaveResult object
65: SaveResult[] srSsu;
66: try
67: {
68: srSsu = binding.create(new sObject[] { ssu });
69: }
70: catch (Exception e)
71: {
72: throw new ApplicationException("Unable to create self-service user for contactid: " + contactId + Environment.NewLine + e.ToString());
73: }
74:
75: // Access the new ID and generate a new password
76: ssuId = srSsu[0].id;
77: string newPassword = null;
78: if (ssuId != null && ssuId != string.Empty)
79: {
80: newPassword = ResetPassword(ssuId);
81: }
82: return newPassword;
83: }