示例#1
0
        public void fetchSummary()
        {
            string[] classNames =
            {
                "Private::Searchable",
                "Private::Crm::Person",
                "Private::Crm::Organisation",
                "Private::Crm::Case"
            };

            Dictionary <string, object> classMetaData = new Dictionary <string, object> ();

            classMetaData.Add("class_names[]", classNames);
            classMetaData.Add("_select_columns[]", columns);

            try {
                WorkbooksApiResponse response = workbooks.assertGet("metadata/types", classMetaData, null);

                workbooks.log("fetchSummary Total: ", new Object[] { response.getTotal() });
                //      if (response.getTotal() != null && response.getTotal() > 0) {
                //        workbooks.log("fetchSummary First: ", new Object[] {response.getFirstData()});
                //      }
            } catch (Exception e) {
                Console.WriteLine("Error while getting the metadata: " + e.Message);
                Console.WriteLine(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#2
0
        /*
         * Fetch four of them back, all available fields
         */
        public void getAPIData()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            //Merge the limit_select and then add array of arrays
            filter3.Add("_sort", "id");
            filter3.Add("_dir", "ASC");
            filter3.Add("_ff[]", new String[] { "key", "key", "key", "key" });
            filter3.Add("_ft[]", new String[] { "eq", "eq", "eq", "eq" });
            filter3.Add("_fc[]", new String[] { "api_data_example: the answer",
                                                "api_data_example: null",
                                                "api_data_example: ten thousand characters",
                                                "api_data_example: multibyte characters" });
            filter3.Add("_fm", "or");

            try {
                WorkbooksApiResponse response = workbooks.assertGet("automation/api_data", filter3, null);

                workbooks.log("getAPIData Total fetched", new Object[] { response.getTotal() });
                workbooks.log("getAPIData First Data", new Object[] { response.getFirstData() });
            } catch (Exception e) {
                workbooks.log("Error while getting the apiData:", new Object[] { e });
                Console.WriteLine(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#3
0
    private void getOrganisations()
    {
        String[] columns = { "id",
                             "lock_version",
                             "name",
                             "object_ref",
                             "main_location[town]",
                             "updated_at",
                             "updated_by_user[person_name]" };
        Dictionary <string, object> filter_limit_select = new Dictionary <string, object> ();

        filter_limit_select.Add("_start", "0");                                   // Starting from the 'zeroth' record
        filter_limit_select.Add("_limit", "100");                                 //   fetch up to 100 records
        filter_limit_select.Add("_sort", "id");                                   // Sort by 'id'
        filter_limit_select.Add("_dir", "ASC");                                   //   in ascending order
        filter_limit_select.Add("_ff[]", "main_location[county_province_state]"); // Filter by this column
        filter_limit_select.Add("_ft[]", "ct");                                   //   containing
        filter_limit_select.Add("_fc[]", "Berkshire");                            //   'Berkshire'
        filter_limit_select.Add("_select_columns[]", columns);                    // An array, of columns to select
        try {
            WorkbooksApiResponse response = workbooks.assertGet("crm/organisations", filter_limit_select, null);
            workbooks.log("Total organisations: ", new Object[] { response.getTotal() });
            workbooks.log("First Organisation: ", new object[] { response.print(response.getFirstData()) });
        } catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }
示例#4
0
        /// <summary>
        /// Gets the people based on the filters given
        /// </summary>
        public void getPeople()
        {
            Dictionary <string, object> filter_limit_select = new Dictionary <string, object> ();

            filter_limit_select.Add("_start", "0");
            filter_limit_select.Add("_limit", "3");
            filter_limit_select.Add("_sort", "id");
            filter_limit_select.Add("_dir", "ASC");
            filter_limit_select.Add("_ff[]", "name");
            filter_limit_select.Add("_ft[]", "bg");
            filter_limit_select.Add("_fc[]", "Alex");
            filter_limit_select.Add("_select_columns[]", columns);
            try {
                WorkbooksApiResponse response = workbooks.get("crm/people", filter_limit_select, null);
                object[]             allData  = response.getData();
                if (allData != null)
                {
                    Console.WriteLine("Response Total: " + response.getTotal());

                    for (int i = 0; i < allData.Length; i++)
                    {
                        Dictionary <string, object> data = (Dictionary <string, object>)allData[i];
                        Console.WriteLine("Person name: " + data["name"] + " Object Ref: " + data["object_ref"]);
                    }
                }
            } catch (Exception wbe) {
                Console.WriteLine("Error while getting the people record: " + wbe.Message);
                Console.WriteLine("Stacktrace: " + wbe);
                testLoginHelper.testExit(workbooks, 1);
            }
        }
示例#5
0
        /*
         * Attempt to fetch an item which does not exist
         */
        public void getNonExistenceAPIData()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            //Merge the limit_select and then add array of arrays
            filter3.Add("_sort", "id");
            filter3.Add("_dir", "ASC");
            filter3.Add("_ff[]", "key");
            filter3.Add("_ft[]", "eq");
            filter3.Add("_fc[]", "api_data_example: no such record exists");

            try {
                WorkbooksApiResponse response = workbooks.assertGet("automation/api_data", filter3, null);

                if (response.getTotal() != 0)
                {
                    workbooks.log("Bad response for non-existent item");
                    login.testExit(workbooks, 1);
                }
            } catch (Exception e) {
                workbooks.log("Error while getting the apiData:", new Object[] { e });
                Console.WriteLine(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#6
0
        // First filter structure: specify arrays for Fields ('_ff[]'), comparaTors ('_ft[]'), Contents ('_fc[]').
        // Note that 'ct' (contains) is MUCH slower than equals. 'not_blank' requires Contents to compare with, but this is ignored.

        public WorkbooksApiResponse  getOrganisationsViaFilter()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            //Merge the limit_select and then add array of arrays
            foreach (string limitKey in limit_select.Keys)
            {
                filter3.Add(limitKey, limit_select [limitKey]);
            }
            filter3.Add("_ff[]", new String[] { "main_location[county_province_state]", "main_location[county_province_state]", "main_location[street_address]" });
            filter3.Add("_ft[]", new String[] { "eq", "ct", "not_blank" });
            filter3.Add("_fc[]", new String[] { "Berkshire", "Yorkshire", "" });

            filter3.Add("_fm", "(1 OR 2) AND 3");                // How to combine the above clauses, without this: 'AND'.
            try {
                WorkbooksApiResponse response3 = workbooks.assertGet("crm/organisations", filter3, null);

                //workbooks.log("getOrganisationsViaFilter First ", new Object[] {response3.getFirstData()});
                Console.WriteLine("Total: " + response3.getTotal());
                object[] allData = response3.getData();
                for (int i = 0; i < allData.Length; i++)
                {
                    Dictionary <string, object> data = (Dictionary <string, object>)allData[i];
                    Console.WriteLine(i + ") " + data["name"] + " - " + data["main_location[county_province_state]"]);
                }
                return(response3);
            } catch (Exception wbe) {
                Console.WriteLine("Error while getting the Organisations record: " + wbe);
                Console.WriteLine(wbe.StackTrace);
                login.testExit(workbooks, 1);
            }
            return(null);
        }
示例#7
0
        public void fetchAll()
        {
            Dictionary <string, object> classMetaData = new Dictionary <string, object> ();

            try {
                WorkbooksApiResponse response = workbooks.assertGet("metadata/types", classMetaData, null);

                workbooks.log("fetchAll Total: ", new Object[] { response.getTotal() });
                //      if (response.getTotal() > 0) {
                //        workbooks.log("fetchAll First: ", new Object[] {response.getFirstData()});
                //      }
            } catch (Exception e) {
                Console.WriteLine("Error while getting the metadata: " + e.Message);
                Console.WriteLine((e.StackTrace));
                login.testExit(workbooks, 1);
            }
        }
示例#8
0
        /*
         * Fetch a single item using the alternate filter syntax
         */
        public void getSingleAPIData()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            filter3.Add("_filter_json", "[['key', 'eq', 'api_data_example: poppins']]");

            try {
                WorkbooksApiResponse response = workbooks.assertGet("automation/api_data", filter3, null);

                workbooks.log("getAPIData Total fetched", new Object[] { response.getTotal() });
                workbooks.log("getAPIData First Data", new Object[] { response.getFirstData() });
            } catch (Exception e) {
                workbooks.log("Error while getting the apiData:", new Object[] { e });
                Console.WriteLine(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#9
0
        /*
         * In order to generate a PDF you need to know the ID of the transaction document (the
         * order, quotation, credit note etc) and the ID of a PDF template. You can find these out
         * for a particular PDF by using the Workbooks Desktop, generating a PDF and examining the
         * URL used to generate the PDF. You will see something like
         *
         *    https://secure.workbooks.com/accounting/sales_orders/11941.pdf?template=232
         *
         * which implies a document ID of 11941 and a template ID of 232. The 'sales_orders' part
         * indicates the type of transaction document you want to reference; see the Workbooks API
         * Reference for a list of the available API endpoints.
         */


        public void generatePDFs()
        {
            Dictionary <string, object> filter_limit_select = new Dictionary <string, object> ();

            filter_limit_select.Add("_start", "0");
            filter_limit_select.Add("_limit", "1");
            filter_limit_select.Add("_sort", "id");
            filter_limit_select.Add("_dir", "ASC");
            filter_limit_select.Add("_select_columns[]", new String[] { "id" });
            try {
                WorkbooksApiResponse response = workbooks.assertGet("accounting/sales_orders", filter_limit_select, null);
                object[]             allData  = response.getData();
                if (allData != null)
                {
                    if (allData.Length != 1)
                    {
                        workbooks.log("generatePDFs: Did not find any orders: ", new Object[] { allData });
                        login.testExit(workbooks, 1);
                    }
                    else
                    {
                        int orderId = (int)((Dictionary <string, object>)allData[0])["id"];
                        // Now generate the PDF

                        String url = "accounting/sales_orders/" + orderId + ".pdf";

                        // Important to add the decode_json as false for PDFs
                        Dictionary <string, object> options = new Dictionary <string, object> ();
                        options.Add("decode_json", false);

                        Dictionary <string, object> templateParams = new Dictionary <string, object> ();
                        templateParams.Add("template", pdfTemplateId);

                        workbooks.get(url, templateParams, options);
                        workbooks.log("generatePDFs finished");
                    }
                }
            } catch (Exception wbe) {
                workbooks.log("Exception while generating PDF", new Object[] { wbe }, "error");
                Console.WriteLine(wbe.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#10
0
        public void fetchSomeMoreSummary()
        {
            string[] classNames =
            {
                "Private::Crm::Case"
            };

            string[] addColumns = { "id",
                                    "lock_version",
                                    "class_name",
                                    "base_class_name",
                                    "human_class_name",
                                    "human_class_name_plural",
                                    "human_class_description",
                                    "instances_described_by",
                                    "icon",
                                    "help_url",
                                    "controller_path",
                                    "fields",
                                    "associations" };


            Dictionary <string, object> classMetaData = new Dictionary <string, object> ();

            classMetaData.Add("class_names[]", classNames);
            classMetaData.Add("_select_columns[]", addColumns);

            try {
                WorkbooksApiResponse response = workbooks.assertGet("metadata/types", classMetaData, null);

                workbooks.log("fetchSomeMoreSummary Total: ", new Object[] { response.getTotal() });
                //      if (response.getTotal() != null && response.getTotal() > 0) {
                //        workbooks.log("fetchSomeMoreSummary First: ", new Object[] {response.getFirstData()});
                //      }
            } catch (Exception e) {
                Console.WriteLine("Error while getting the metadata: " + e.Message);
                Console.WriteLine((e.StackTrace));
                login.testExit(workbooks, 1);
            }
        }
示例#11
0
        // The equivalent using a second filter structure: a JSON-formatted string  array of arrays containg 'field, comparator, contents'
        public WorkbooksApiResponse getOrganisationsViaFilterJson()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            /*
             * Syntax to create array of arrays is
             * 1) [[a, b, c], [x,y,z], [1,2,3]]; Note the two square brackets
             * 2) new String[][] {new string[]{a,b,c}, new string[] {x,y,z},new string[] {1,2,3}} see the above method for this syntax
             */
            //Merge the limit_select and then add array of arrays
            foreach (string limitKey in limit_select.Keys)
            {
                filter3.Add(limitKey, limit_select [limitKey]);
            }
            filter3.Add("_filter_json", "[" +
                        "['main_location[county_province_state]', 'eq', 'Berkshire']," +
                        "['main_location[county_province_state]', 'ct', 'Yorkshire']," +
                        "['main_location[street_address]', 'not_blank', '']" +
                        "]");
            filter3.Add("_fm", "(1 OR 2) AND 3");

            try{
                WorkbooksApiResponse response3 = workbooks.assertGet("crm/organisations", filter3, null);

                //workbooks.log("getOrganisationsViaFilterJson First: ", new Object[] {response3.getFirstData()});
                Console.WriteLine("Total: " + response3.getTotal());
                object[] allData = response3.getData();
                for (int i = 0; i < allData.Length; i++)
                {
                    Dictionary <string, object> data = (Dictionary <string, object>)allData[i];
                    Console.WriteLine(i + ") " + data["name"] + " - " + data["main_location[county_province_state]"]);
                }
                return(response3);
            } catch (Exception wbe) {
                Console.WriteLine("Error while getting the organisations record: " + wbe.Message);
                Console.WriteLine(wbe.StackTrace);
                login.testExit(workbooks, 1);
            }
            return(null);
        }
示例#12
0
        /// <summary>
        /// Alternatively, choose a template and a Case then use it to create a Draft email about the Case.
        /// </summary>
        public static void sendDraftTemplatedEmail()
        {
            List <Dictionary <string, object> > templatedEmailList = new List <Dictionary <string, object> >();

            Dictionary <string, object> templatedEmail = new Dictionary <string, object>();

            templatedEmail.Add("render_with_template_name", "Autotest Template");
            templatedEmail.Add("render_with_resource_type", "Private::Crm::Case");
            templatedEmail.Add("render_with_resource_id", 2);
            templatedEmail.Add("from_address", "*****@*****.**");
            templatedEmail.Add("to_addresses", "[email protected], [email protected]");
            templatedEmail.Add("cc_addresses", "[email protected], [email protected]");
            templatedEmail.Add("bcc_addresses", "*****@*****.**");
            templatedEmail.Add("status", "DRAFT");

            templatedEmailList.Add(templatedEmail);
            try {
                WorkbooksApiResponse response = workbooks.assertCreate("email/emails", templatedEmailList, null, null);

                List <Dictionary <string, object> > idVersionObjects = workbooks.idVersions(response);

                /*
                 * Now change the status to send it
                 */
                Dictionary <string, object> updateEmail = new Dictionary <string, object> ();
                updateEmail.Add("id", ((Dictionary <string, object>)idVersionObjects[0])["id"]);
                updateEmail.Add("lock_version", ((Dictionary <string, object>)idVersionObjects[0])["lock_version"]);
                updateEmail.Add("status", "SEND");

                List <Dictionary <string, object> > updateEmailList = new List <Dictionary <string, object> >();
                updateEmailList.Add(updateEmail);
                response = workbooks.assertUpdate("email/emails", updateEmailList, null, null);
                workbooks.log("sendDraftTemplatedEmail() : Email is sent successfully");
            } catch (Exception e) {
                workbooks.log("Error while sending templated Email " + e.Message);
                workbooks.log(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
示例#13
0
        // The equivalent using a third filter structure: an array of filters, each containg 'field, comparator, contents'.

        public WorkbooksApiResponse  getOrganisationsViaFilterArray()
        {
            Dictionary <string, object> filter3 = new Dictionary <string, object> ();

            /*			 Merge the limit_select and then add array of arrays
             * Syntax to create array of arrays is
             * 1) [[a, b, c], [x,y,z], [1,2,3]]; Note the two square brackets . See below method for example
             * 2) new String[][] {new string[]{a,b,c}, new string[] {x,y,z},new string[] {1,2,3}}
             */
            //Merge the limit_select and then add array of arrays
            foreach (string limitKey in limit_select.Keys)
            {
                filter3.Add(limitKey, limit_select [limitKey]);
            }
            filter3.Add("_filters[]", new String[][] {
                new string[] { "main_location[county_province_state]", "eq", "Berkshire" },
                new string[] { "main_location[county_province_state]", "ct", "Yorkshire" },
                new string[] { "main_location[street_address]", "not_blank", "" }
            });
            filter3.Add("_fm", "(1 OR 2) AND 3");                // How to combine the above clauses, without this: 'AND'.
            try {
                WorkbooksApiResponse response3 = workbooks.assertGet("crm/organisations", filter3, null);
                Console.WriteLine("Total: " + response3.getTotal());
                //workbooks.log("getOrganisationsViaFilterArray First: ", new Object[] {response3.getFirstData()});

                object[] allData = response3.getData();
                for (int i = 0; i < allData.Length; i++)
                {
                    Dictionary <string, object> data = (Dictionary <string, object>)allData[i];
                    Console.WriteLine(i + ") " + data["name"] + " - " + data["main_location[county_province_state]"]);
                }
                return(response3);
            } catch (Exception wbe) {
                Console.WriteLine("Error while getting the organisations record: " + wbe.Message);
                Console.WriteLine(wbe.StackTrace);
                login.testExit(workbooks, 1);
            }
            return(null);
        }
示例#14
0
    private void createOrganisations(bool doUpdate, bool doDelete, bool doBatch)
    {
        List <Dictionary <string, object> > objectIdLockVersion = null;

        try{
            //*************Multiple Organisations
            Dictionary <string, object>         org2 = new Dictionary <string, object>();
            Dictionary <string, object>         org3 = new Dictionary <string, object>();
            Dictionary <string, object>         org4 = new Dictionary <string, object>();
            List <Dictionary <string, object> > multipleOrganisations = new List <Dictionary <string, object> >();

            org2.Add("name", "Freedom & Light Ltd");
            org2.Add("created_through_reference", "12345");
            org2.Add("industry", "Media & Entertainment");
            org2.Add("main_location[country]", "United Kingdom");
            org2.Add("main_location[county_province_state]", "Berkshire");
            org2.Add("main_location[fax]", "0234 567890");
            org2.Add("main_location[postcode]", "RG99 9RG");
            org2.Add("main_location[street_address]", "100 Main Street");
            org2.Add("main_location[telephone]", "0123 456789");
            org2.Add("main_location[town]", "Beading");
            org2.Add("no_phone_soliciting", true);
            org2.Add("no_post_soliciting", true);
            org2.Add("organisation_annual_revenue", "10000000");
            org2.Add("organisation_category", "Marketing Agency");
            org2.Add("organisation_company_number", "12345678");
            org2.Add("organisation_num_employees", 250);
            org2.Add("organisation_vat_number", "GB123456");
            org2.Add("website", "www.freedomandlight.com");

            org3.Add("name", "Freedom Power Tools Limited");
            org3.Add("created_through_reference", "12346");

            org4.Add("name", "Freedom o\" the Seas Recruitment");
            org4.Add("created_through_reference", "12347");

            multipleOrganisations.Add(org2);
            multipleOrganisations.Add(org3);
            multipleOrganisations.Add(org4);

            WorkbooksApiResponse response = workbooks.assertCreate("crm/organisations", multipleOrganisations, null, null);

            workbooks.log("createOrganisations Multiple: ", new Object[] { response.print(response.getFirstAffectedObject()) });
            objectIdLockVersion = workbooks.idVersions(response);

            // **************** UPDATE THE CREATED ORGANISATION RECORDS
            if (doUpdate)
            {
                // Clear the hashmaps to populate with the details to update
                multipleOrganisations.Clear();
                org2.Clear();
                org3.Clear();
                org4.Clear();

                org2.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                org2.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                org2.Add("name", "Freedom & Light Unlimited");
                org2.Add("main_location[postcode]", "RG66 6RG");
                org2.Add("main_location[street_address]", "199 High Street");

                org3.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                org3.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);
                org3.Add("name", "Freedom Power");

                org4.Add("id", ((Dictionary <string, object>)objectIdLockVersion[2])["id"]);
                org4.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[2])["lock_version"]);
                org4.Add("name", "Sea Recruitment");

                multipleOrganisations.Add(org2);
                multipleOrganisations.Add(org3);
                multipleOrganisations.Add(org4);

                response = workbooks.assertUpdate("crm/organisations", multipleOrganisations, null, null);
                workbooks.log("Updated organisations ", new Object[] { response.print(response.getFirstAffectedObject()) });
            }
            objectIdLockVersion = workbooks.idVersions(response);

            if (doBatch)
            {
                //************** BATCH ALL
                Dictionary <string, object>         createAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         updateAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         deleteAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         deleteAnotherAction = new Dictionary <string, object> ();
                List <Dictionary <string, object> > batchActions        = new List <Dictionary <string, object> >();


                createAction.Add("method", "CREATE");
                createAction.Add("name", "Abercrombie Pies");
                createAction.Add("industry", "Food");
                createAction.Add("main_location[country]", "United Kingdom");
                createAction.Add("main_location[county_province_state]", "Berkshire");
                createAction.Add("main_location[town]", "Beading");

                updateAction.Add("method", "UPDATE");
                updateAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                updateAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                updateAction.Add("name", "Lights \'R Us");
                updateAction.Add("main_location[postcode]", null);

                deleteAction.Add("method", "DELETE");
                deleteAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                deleteAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);

                deleteAnotherAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[2])["id"]);
                deleteAnotherAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[2])["lock_version"]);
                deleteAnotherAction.Add("method", "DELETE");

                batchActions.Add(createAction);
                batchActions.Add(updateAction);
                batchActions.Add(deleteAction);
                batchActions.Add(deleteAnotherAction);

                response = workbooks.assertBatch("crm/organisations", batchActions, null, null, null);
                workbooks.log("Batch Actions: ", new Object[] { response.print(response.getFirstAffectedObject()) });
            }
            objectIdLockVersion = workbooks.idVersions(response);

            //************** CREATE A SINGLE ORGANISATION
            List <Dictionary <string, object> > singleOrganisation = new List <Dictionary <string, object> >();
            Dictionary <string, object>         org1 = new Dictionary <string, object>();

            org1.Add("name", "Birkbeck Burgers");
            org1.Add("industry", "Food");
            org1.Add("main_location[country]", "United Kingdom");
            org1.Add("main_location[county_province_state]", "Oxfordshire");
            org1.Add("main_location[town]", "Oxford");

            singleOrganisation.Add(org1);
            response = workbooks.assertCreate("crm/organisations", singleOrganisation, null, null);
            workbooks.log("createOrganisations Single: ", new Object[] { response.getFirstAffectedObject() });
            List <Dictionary <string, object> > createdObjectIdLockVersion = workbooks.idVersions(response);

            createdObjectIdLockVersion.Add((Dictionary <string, object>)objectIdLockVersion[0]);
            createdObjectIdLockVersion.Add((Dictionary <string, object>)objectIdLockVersion[1]);
            //***************** DELETE THE REMAIIG ORGANISATIONS CREATED IN THIS CLASS
            if (doDelete)
            {
                workbooks.assertDelete("crm/organisations", createdObjectIdLockVersion, null, null);
                workbooks.log("Delete Organisations ");
            }
        } catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }
示例#15
0
        /// <summary>
        /// Create two people, tagging with their identifiers in the external system. Up to 100 can be done in one batch.
        /// </summary>
        /// <param name="doUpdate">If set to <c>true</c> do update on the created people record.</param>
        /// <param name="doDelete">If set to <c>true</c> do delete on the created people record.</param>
        private void createTwoPeople(bool doUpdate, bool doDelete)
        {
            List <Dictionary <string, object> > twoPeople = new List <Dictionary <string, object> >();

            Dictionary <string, object>         person1             = new Dictionary <string, object>();
            List <Dictionary <string, object> > objectIdLockVersion = null;

            person1.Add("name", "Csharp Rich Richards");
            person1.Add("created_through_reference", "101");
            person1.Add("main_location[country]", "UK");
            person1.Add("main_location[county_province_state]", "Berkshire");
            person1.Add("main_location[fax]", "01234 54646");
            person1.Add("main_location[postcode]", "RG6 1AZ");
            person1.Add("main_location[street_address]", "100 Civvy Street");
            person1.Add("main_location[telephone]", "011897656");
            person1.Add("main_location[town]", "Reading");
            person1.Add("no_email_soliciting", false);
            person1.Add("no_phone_soliciting", true);
            person1.Add("no_post_soliciting", true);
            person1.Add("person_first_name", "Richard");
            person1.Add("person_middle_name", "");
            person1.Add("person_last_name", "Richards");
            person1.Add("person_personal_title", "Mr.");
            person1.Add("website", "www.richards.me.uk");

            Dictionary <string, object> person2 = new Dictionary <string, object>();

            //String[][] person2 = ...
            person2.Add("name", "Csharp Stevie Stephens");
            person2.Add("created_through_reference", "102");
            person2.Add("main_location[country]", "UK");
            person2.Add("main_location[county_province_state]", "Berkshire");
            person2.Add("main_location[fax]", "01234 54646");
            person2.Add("main_location[postcode]", "RG6 1AZ");
            person2.Add("main_location[street_address]", "102 Castle Street");
            person2.Add("main_location[telephone]", "011897656");
            person2.Add("main_location[town]", "Reading");
            person2.Add("no_email_soliciting", false);
            person2.Add("no_phone_soliciting", true);
            person2.Add("no_post_soliciting", true);
            person2.Add("person_first_name", "Steve");
            person2.Add("person_middle_name", "");
            person2.Add("person_last_name", "Stephens");
            person2.Add("person_personal_title", "Mr.");
            person2.Add("website", "www.steve.me.uk");


            twoPeople.Add(person1);
            twoPeople.Add(person2);
            try {
                WorkbooksApiResponse response = workbooks.assertCreate("crm/people", twoPeople, null, null);

                object[] allData = response.getAffectedObjects();

                for (int i = 0; i < allData.Length; i++)
                {
                    Dictionary <string, object> data = (Dictionary <string, object>)allData[i];
                    Console.WriteLine("Person name: " + data["name"] + " Object Ref: " + data["object_ref"]);
                }

                // **************** UPDATE THE TWO CREATED PEOPLE RECORDS
                if (doUpdate)
                {
                    objectIdLockVersion = workbooks.idVersions(response);

                    // Clear the hashmaps to populate with the details to update
                    twoPeople.Clear();
                    person1.Clear();
                    person2.Clear();

                    person1.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                    person1.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                    person1.Add("main_location[email]", "*****@*****.**");

                    person2.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                    person2.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);
                    person2.Add("main_location[email]", "*****@*****.**");

                    twoPeople.Add(person1);
                    twoPeople.Add(person2);

                    workbooks.assertUpdate("crm/people", twoPeople, null, null);
                    Console.WriteLine("Updated people. ");
                    //workbooks.log("update_two_people", new Object[] {responseUpdate.getFirstAffectedObjects()});
                }
                //***************** DELETE THE TWO CREATED PEOPLE
                if (doDelete)
                {
                    objectIdLockVersion = workbooks.idVersions(response);

                    WorkbooksApiResponse responseDelete = workbooks.assertDelete("crm/people", objectIdLockVersion, null, null);

                    workbooks.log("delete_two_people", new Object[] { responseDelete.getFirstAffectedObject() });
                }
            } catch (Exception wbe) {
                Console.WriteLine("Error while creating the people record: " + wbe.Message);
                Console.WriteLine(wbe.StackTrace);
                testLoginHelper.testExit(workbooks, 1);
            }
        }