public void FillCustomFieldResponseList( int registrationID, List<CustomFieldResponses> targetList, int cfID, string description, int category, string response, string amount, string code) { CustomFieldResponse customFieldResponse = new CustomFieldResponse(); customFieldResponse.code = code; customFieldResponse.category = category; customFieldResponse.customFieldDescription = description; customFieldResponse.customFieldId = cfID; customFieldResponse.response = response; customFieldResponse.amount = amount; if (targetList.Exists(s => s.RegistrationID == registrationID)) { CustomFieldResponses existedResponses = targetList.Find(s => s.RegistrationID == registrationID); if (existedResponses.customFields == null) { existedResponses.customFields = new Dictionary<int, CustomFieldResponse>(); existedResponses.customFields.Add( customFieldResponse.customFieldId, customFieldResponse); } else { if (existedResponses.customFields.ContainsKey(customFieldResponse.customFieldId)) { existedResponses.customFields[customFieldResponse.customFieldId] = customFieldResponse; } else { existedResponses.customFields.Add( customFieldResponse.customFieldId, customFieldResponse); } } } else { CustomFieldResponses cfResponses = new CustomFieldResponses(); cfResponses.RegistrationID = registrationID; cfResponses.customFields.Add(customFieldResponse.customFieldId, customFieldResponse); targetList.Add(cfResponses); } }
public void UpdateMembers() { string internalValue = string.Empty; string guid; CustomFieldResponse testCustomField; string strCustomFieldCode = "testcustomfield"; //Get a few Member IDs (added since the first of this year) ApiResponse response = manager.SaPeopleAllGetIDs(new DateTime(DateTime.Now.Year, 1, 1), null); if (response.ErrorCode != ApiErrorCode.NoError) { //Error fetching IDs. Check your configuration and try again. Console.WriteLine("Unable to fetch MemberIDs. Check your configuration values and try again."); return; } List <DataItem> peopleIDs = response.MethodResults.GetNamedItem("People").Items; int peopleIDCount = peopleIDs.Count; MemberProfile profile; List <CustomFieldResponse> customFields; if (peopleIDs.Count > 50) { //Take X people off the top (rather than process them all and hog resources) peopleIDs = peopleIDs.Take(50).ToList(); } foreach (DataItem item in peopleIDs) { internalValue = string.Empty; guid = item.Value; Console.WriteLine("Processing member guid: " + guid); //Get Profile information for this Person response = manager.SaPeopleProfileGet(guid); if (response.ErrorCode == ApiErrorCode.NoError) { //Get person profile profile = response.MethodResults.ConvertTo <MemberProfile>(); //Get an internal value for this member (some arbirary data from Client system) internalValue = GetInternalValueForMember(profile.ConstituentID); //Make sure we have an internal value to update with if (!string.IsNullOrEmpty(internalValue)) { //From there, get CustomFieldResponses customFields = profile.CustomFieldResponses; //Optional: update standard profile fields here profile.LastUpdated = DateTime.Now; //Check for existence of a given custom field response, by FieldCode testCustomField = customFields.SingleOrDefault(x => x.FieldCode != null && x.FieldCode.Equals(strCustomFieldCode)); if (testCustomField == null) { //User has no response for this field....create one testCustomField = new CustomFieldResponse(); testCustomField.FieldCode = strCustomFieldCode; testCustomField.Values.Add(internalValue); customFields.Add(testCustomField); } else { //User already has a value in this field...update it testCustomField.Values[0] = internalValue; } //Update this person profile response = manager.SaPeopleProfileUpdate(profile.Serialize()); if (response.ErrorCode != ApiErrorCode.NoError) { Console.WriteLine(string.Format("ERROR: SaPeopleProfileUpdate call failed. Details: {0} - {1}", response.ErrorCode, response.ErrorMessage)); } } } } }