/// <summary>
        /// Given a known list of registrations (by ID) and custom field checkboxes (by ID), 
        /// creates a response for each custom field checkbox for all registrations
        /// </summary>
        private static void createCustomFieldResponses(RegOnlineAPIProxy.RegOnlineAPISoapClient service)
        {
            List<int> regIDs = new List<int>()
                {
                    1,2,3 //{ your list of registrants which need custom field responses to checkboxes created }
                };

            foreach (int registrationID in regIDs)
            {
                // Get the registrant
                Console.WriteLine("calling GetRegistration");
                RegOnlineAPIProxy.ResultsOfListOfRegistration getRegResults = service.GetRegistration(null, registrationID);

                if (getRegResults.Success)
                {
                    // API instance of the current registration
                    RegOnlineAPIProxy.APIRegistration registration = getRegResults.Data[0];

                    List<int> CFIDs = new List<int>()
                        {
                            7,8,9 //{ your list of custom fields which need responses created for each registrant in List<int> regIDs }
                        };

                    List<RegOnlineAPIProxy.APICustomFieldResponse> responses = new List<APICustomFieldResponse>();

                    // create a list of responses to each checkbox in List<int> CFIDs for the current registration
                    foreach (int cfID in CFIDs)
                    {
                        RegOnlineAPIProxy.APICustomFieldResponse newResponse =
                            new RegOnlineAPIProxy.APICustomFieldResponse();
                        newResponse.CFID = cfID;
                        newResponse.RegistrationID = registrationID;
                        newResponse.EventID = registration.EventID;
                        newResponse.Response = "True"; // set response to True for checkbox
                        responses.Add(newResponse);
                    }

                    // push all new custom field responses via API for the current registration
                    RegOnlineAPIProxy.ResultsOfBoolean updateResults =
                        service.UpdateCustomFieldResponsesForRegistration(null, registration.EventID, registrationID, responses.ToArray());

                    // handle API response
                    if (updateResults.Success)
                    {
                        Console.WriteLine(
                            "UpdateCustomFieldResponsesForRegistration succeeded - {0} responses added for reg {1} {2}."
                            , responses.Count, registration.FirstName, registration.LastName);
                    }
                    else
                    {
                        Console.WriteLine(updateResults.Message);
                    }

                    System.Threading.Thread.Sleep(100); // add delay between each registrant to prevent exceeding ROL API usage throttling limit, if necessary
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Prompts for registration ID and custom field ID then updates or inserts 
        /// a response for the provided custom field to a new list item
        /// </summary>
        private static void UpsertMultipleChoiceCustomFieldResponse(RegOnlineAPIProxy.RegOnlineAPISoapClient service)
        {
            // Prompt for registration ID
            int registrationID = 0;
            do
            {
                Console.WriteLine("Enter the ID of the registrant you wish to update a response for.");
                string providedRegID = Console.ReadLine();

                if (!int.TryParse(providedRegID, out registrationID) || (registrationID <= 0))
                {
                    Console.WriteLine("Invalid registration ID.");
                }

            } while (registrationID <= 0);

            // Prompt for custom field ID
            int cfID = 0;
            do
            {
                Console.WriteLine("Enter the ID of the custom field that the registrant you are updating selected a multiple choice item for.");
                string providedCFID = Console.ReadLine();

                if (!int.TryParse(providedCFID, out cfID) || (cfID <= 0))
                {
                    Console.WriteLine("Invalid custom field ID.");
                }

            } while (cfID <= 0);

            // Get the registrant
            Console.WriteLine("calling GetRegistration");
            RegOnlineAPIProxy.ResultsOfListOfRegistration getRegResults = service.GetRegistration(null, registrationID);

            if (getRegResults.Success)
            {
                // API instance of the provided registration
                RegOnlineAPIProxy.APIRegistration registration = getRegResults.Data[0];

                // Get responses for the provided registrant
                Console.WriteLine("calling GetAgendaItemResponsesForRegistration");
                RegOnlineAPIProxy.ResultsOfListOfCustomFieldResponse getResponsesResults = service.GetAgendaItemResponsesForRegistration(null, registration.EventID, registrationID, string.Empty);

                if (getResponsesResults.Success)
                {
                    RegOnlineAPIProxy.APICustomFieldResponse responseToUpsert = getResponsesResults.Data.Where(r => r.CFID == cfID).FirstOrDefault();

                    // Now display list items to select from
                    // With the API Token passed as an HTTP Header (above) instead of a SOAP Header, the first parameter for GetEvents below can be null.
                    RegOnlineAPIProxy.ResultsOfListOfCustomFieldListItem getCFLIResults = service.GetCustomFieldListItems(null, registration.EventID, cfID, "IsVisible", "Order ASC");

                    if (getCFLIResults.Success)
                    {
                        // display available list items
                        Console.WriteLine(System.Environment.NewLine);
                        foreach (var result in getCFLIResults.Data)
                        {
                            Console.WriteLine("Item: {0} (ID: {1})", result.NameOnForm, result.ID);
                        }
                        Console.WriteLine(System.Environment.NewLine);

                        if (responseToUpsert == null)
                        {
                            // create a new response
                            responseToUpsert = new RegOnlineAPIProxy.APICustomFieldResponse();                            
                            responseToUpsert.CFID = cfID;
                            responseToUpsert.RegistrationID = registrationID;
                            responseToUpsert.EventID = registration.EventID;
                            
                            Console.WriteLine("Registrant {0} {1} does not currently have a selection for this multiple choice custom field.",
                                registration.FirstName, registration.LastName);
                            Console.WriteLine("Select an item from the list above to create a response to and enter the ID followed by [Enter].");                            
                        }
                        else
                        {
                            // existing response found
                            Console.WriteLine("The currently selected multiple choice item is {0} (ID: {1}).", 
                                responseToUpsert.ItemDescription, responseToUpsert.ItemID);
                            Console.WriteLine("Select an item from the list above to update this response to and enter the ID followed by [Enter].");
                        }

                        // get list item to upsert response with
                        int newItemID = 0;
                        do
                        {
                            string providedItemID = Console.ReadLine();

                            if (!int.TryParse(providedItemID, out newItemID) || (newItemID <= 0))
                            {
                                Console.WriteLine("Invalid list item ID.");
                            }

                        } while (newItemID <= 0);

                        // set the Response value to upsert the selected item ID / Description
                        responseToUpsert.Response = newItemID.ToString();

                        RegOnlineAPIProxy.ResultsOfBoolean updateResults =
                            service.UpdateCustomFieldResponsesForRegistration(null, registration.EventID, registrationID, new RegOnlineAPIProxy.APICustomFieldResponse[] { responseToUpsert });

                        if (updateResults.Success)
                        {
                            Console.WriteLine("UpdateCustomFieldResponsesForRegistration succeeded.");
                        }
                    }
                }
            }
        }