Beispiel #1
0
        /*  Remove comment to test.
         * [Fact]
         */
        public async void WikiReadLeadsWithQueryTest()
        {
            string url      = "http://191.101.224.189/sugar/service/v4_1/rest.php";
            string username = "******";
            string password = "******";

            var client = new SugarRestClient(url, username, password);

            var request = new SugarRestRequest(RequestType.BulkRead);

            List <string> selectedFields = new List <string>();

            selectedFields.Add("id");
            selectedFields.Add("name");
            selectedFields.Add("modified_by_name");

            request.Options.SelectFields = selectedFields;

            // Set query
            request.Options.Query = "leads.id IN('10d82d59-08eb-8f0d-28e0-5777b57af47c', '12037cd0-ead2-402e-e1d0-5777b5dfb965', '13d4109d-c5ca-7dd1-99f1-5777b57ef30f', '14c136e5-1a67-eeba-581c-5777b5c8c463', '14e4825e-9573-4d75-2dbe-5777b5b7ee85', '1705b33a-3fad-aa70-77ef-5777b5b081f1', '171c1d8b-e34f-3a1f-bef7-5777b5ecc823', '174a8fc4-56e6-3471-46d8-5777b565bf5b', '17c9c496-90a1-02f5-87bd-5777b51ab086', '1d210352-7a1f-2c5d-04ae-5777b5a3312f')";

            SugarRestResponse response = await client.ExecuteAsync <Lead>(request);

            List <Lead> leads = (List <Lead>)response.Data;
            // -------------------End Bulk Read Account-------------------
        }
Beispiel #2
0
        /*  Remove comment to test.
         * [Fact]
         */
        public async void WikiReadCasesWithQueryPredicatesTest()
        {
            string url      = "http://191.101.224.189/sugar/service/v4_1/rest.php";
            string username = "******";
            string password = "******";

            var client = new SugarRestClient(url, username, password);

            var request = new SugarRestRequest(RequestType.BulkRead);

            request.Options.MaxResult = 3;

            request.Options.QueryPredicates = new List <QueryPredicate>();
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Name), QueryOperator.StartsWith, "Warning"));
            request.Options.QueryPredicates.Add(new QueryPredicate("name", QueryOperator.Contains, "message"));
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Status), QueryOperator.Equal, "Assigned"));
            DateTime date = DateTime.Parse("07/02/2016");

            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.DateEntered), QueryOperator.Between, null, date.AddDays(-1), DateTime.Now));

            SugarRestResponse response = await client.ExecuteAsync <Case>(request);

            List <Case> cases = (List <Case>)response.Data;
            // -------------------End Bulk Read Account-------------------
        }
Beispiel #3
0
        /*  Remove comment to test.
         * [Fact]
         */
        public async void WikiReadContactsByPageAsyncTest()
        {
            // using SugarRestSharp;

            string url      = "http://191.101.224.189/sugar/service/v4_1/rest.php";
            string username = "******";
            string password = "******";

            var client  = new SugarRestClient(url, username, password);
            var request = new SugarRestRequest(RequestType.PagedRead);

            // Select fields.
            List <string> selectFields = new List <string>();

            selectFields.Add(nameof(Contact.FirstName));

            // You can mix C# type and json type.
            selectFields.Add("last_name");

            request.Options.SelectFields = selectFields;

            // Sets page options
            request.Options.CurrentPage   = 1;
            request.Options.NumberPerPage = 10;
            SugarRestResponse response = await client.ExecuteAsync <Contact>(request);

            List <Contact> cases = (List <Contact>)response.Data;
            // -------------------End Bulk Read Account-------------------
        }
Beispiel #4
0
        public async void ReadBulkAsyncWithQueryTest()
        {
            var client = new SugarRestClient(TestAccount.Url, TestAccount.Username, TestAccount.Password);

            // -------------------Bulk Read Account-------------------
            int count = 25;

            var request = new SugarRestRequest("Cases", RequestType.BulkRead);

            request.Options.QueryPredicates = new List <QueryPredicate>();
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Name), QueryOperator.StartsWith, "Warning"));
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Name), QueryOperator.Contains, "message"));
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.Status), QueryOperator.Equal, "Assigned"));
            DateTime date = DateTime.Parse("07/02/2016");

            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Case.DateEntered), QueryOperator.Between, null, date.AddDays(-1), DateTime.Now));
            request.Options.MaxResult = count;

            SugarRestResponse response = await client.ExecuteAsync <Case>(request);

            Assert.NotNull(response);
            Assert.Equal(response.StatusCode, HttpStatusCode.OK);

            List <Case> readACases = (List <Case>)response.Data;

            Assert.NotNull(readACases);
            Assert.True(readACases.Count <= count);
            Assert.True(readACases.All(x => x.Name.StartsWith("Warning")));
            Assert.True(readACases.All(x => x.Name.Contains("message")));
            Assert.True(readACases.All(x => x.Status == "Assigned"));

            // -------------------End Bulk Read Account-------------------
        }
Beispiel #5
0
        public static async Task <SugarRestResponse> DeleteAccountAsync(SugarRestClient client, string accountId)
        {
            var request = new SugarRestRequest("Accounts", RequestType.Delete);

            request.Parameter = accountId;

            return(await client.ExecuteAsync <Account>(request));
        }
Beispiel #6
0
        public static async Task <SugarRestResponse> DeleteContactAsync(SugarRestClient client, string contactId)
        {
            var request = new SugarRestRequest("Contacts", RequestType.Delete);

            request.Parameter = contactId;

            return(await client.ExecuteAsync <Contact>(request));
        }
Beispiel #7
0
        public static async Task <SugarRestResponse> CreateAccountAsync(SugarRestClient client, Account account)
        {
            var request = new SugarRestRequest(RequestType.Create);

            request.Parameter = account;

            request.Options.SelectFields = GetSelectedField();

            return(await client.ExecuteAsync <Account>(request));
        }
Beispiel #8
0
        public static async Task <SugarRestResponse> ReadAccountAsync(SugarRestClient client, string accountId)
        {
            var request = new SugarRestRequest(RequestType.ReadById);

            request.Parameter = accountId;

            request.Options.SelectFields = GetSelectedField();
            request.Options.SelectFields.Add(nameof(Account.Id));

            return(await client.ExecuteAsync <Account>(request));
        }
Beispiel #9
0
        public static async Task <SugarRestResponse> BulkReadAccountAsync(SugarRestClient client, int count)
        {
            var request = new SugarRestRequest();

            request.RequestType = RequestType.BulkRead;

            request.Options.SelectFields = GetSelectedField();
            request.Options.SelectFields.Add(nameof(Account.Id));

            request.Options.MaxResult = count;

            return(await client.ExecuteAsync <Account>(request));
        }
Beispiel #10
0
        /*  Remove comment to test.
         * [Fact]
         */
        public async void WikiReadAccountsWithQueryIgnorePredicatesTest()
        {
            string url      = "http://191.101.224.189/sugar/service/v4_1/rest.php";
            string username = "******";
            string password = "******";

            var client = new SugarRestClient(url, username, password);

            var request = new SugarRestRequest(RequestType.BulkRead);

            request.Options.Query           = "accounts.name = 'Air Safety Inc' ";
            request.Options.QueryPredicates = new List <QueryPredicate>();
            request.Options.QueryPredicates.Add(new QueryPredicate(nameof(Account.Name), QueryOperator.Equal, "General Electric USA, Inc"));

            SugarRestResponse response = await client.ExecuteAsync <Account>(request);

            List <Account> accounts = (List <Account>)response.Data;
            // -------------------End Bulk Read Account-------------------
        }