Skip to content

Asynchronous Actions

Dan Lively edited this page Feb 18, 2014 · 2 revisions

SugarSharp also provides the ability to modify data asynchronously.

###Create

SugarClient Sugar = new SugarClient(url, username, passsword);
            
object bean = new
{
  name = "Async Testing",
  phone_office = "333-443-3552",
  description = "Testing out async method calls from C#"
};


Sugar.CreateAsync("Accounts", bean, (success, responseId) =>
{
    if (success)
    {
      Console.WriteLine("1st result {0}", responseId);
    }

});
            

###Update

SugarClient Sugar = new SugarClient(url, username, passsword);
String recordID = "<<record_id>>";

object bean = new
{
  name = "Async Update Test Account",
  phone_office = "333-443-3552",
  description = "Update the record description"
};

Sugar.UpdateAsync("Accounts",recordID, bean, (success, responseId) =>
{
    if (success)
    {
        Console.WriteLine("1st result {0}", responseId);
    }

});

###Delete

SugarClient Sugar = new SugarClient(url, username, passsword);
String recordID = "<<record_id>>";

Sugar.DeleteAsync("Accounts", recordID, (success, responseId) => 
{
    if (success)
    {
        Console.WriteLine("Record Deleted : {0}", responseId);
    }
});
Clone this wiki locally