Hi all, (or BenBusse)
Supposed I want to update a single record and I just want to target a single field.
example:
Table : Person
Fields : FirstName, LastName, Age
Now I want to change the name only but keep the last name and age. So far I have a two async methods.
When I do this, it wipes out other other values and put the new values I’ve just defined.
How Do I just update the firstname or that single key/field?
static void Main(string[] args)
{
Client client = new Client { id= 4, FirstName = "New Name" };
updateRecord(4,client);
Console.ReadLine();
}
static async void updateRecord(int id, object obj)
{
RESTCall api = new RESTCall("appname");
string body = JsonConvert.SerializeObject(obj);
IHttpResponse response = await api.UpdateRecord(Tables.TBL_MAC, id, body);
Console.WriteLine(string.Format("Code: {0} , Body: {1} ", response.Code, response.Body));
return;
}
class RESTCall
{
public async Task<IHttpResponse> UpdateRecord(string table, int id, string body)
{
string uri = this.DB_Uri + table + "/" + id;
HttpHeaders header = new HttpHeaders();
header.AddOrUpdate("X-DreamFactory-Application-Name", App_Name);
IHttpRequest request = new HttpRequest(HttpMethod.Put, uri, header, body);
IHttpFacade httpFacade = new UnirestHttpFacade();
IHttpResponse response = await httpFacade.RequestAsync(request);
return response;
}
}