Skip to content

Instantly share code, notes, and snippets.

@dlively1
Created November 14, 2013 05:02
Show Gist options
  • Save dlively1/7461681 to your computer and use it in GitHub Desktop.
Save dlively1/7461681 to your computer and use it in GitHub Desktop.
using linq to filter a results set through the API
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SugarRest;
using SugarRest.Exceptions;
using SugarRest.Model;
using SugarRest.Extensions;
namespace SugarRestTesting
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting Client ...");
string url = "https://<instance>/rest/v10/";
string username = "admin";
string password = "password";
SugarClient sugar = new SugarClient(url, username, password);
Console.WriteLine("connected ...");
var options = new SearchOptions();
options.query = "a";
var results = sugar.GetBeans<Account>("Accounts", options);
if (results.records != null)
{
if (results.records.Count > 0)
{
//Linq query
var consultingFirms = from account in results.records
where account.industry == "Consulting"
select account;
if (consultingFirms != null)
{
foreach (var a in consultingFirms)
{
Console.WriteLine(a.name);
}
}
}
}
Console.WriteLine("Finished Test");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment