I am using xamarin c# and Mvvmcross.
I am able to do a Get using the below code which returns a List of MyObject.
How can I change this so that I can edit a MyObject?
I would like to do soothing like:
url = "http://address/api/MyObject/myId";
request.Method = "Put";
request.SecondParamOfWebAPICall = new MyObject(){ObjectId = "myId", FieldToChange = "123"};
But then i am not sure how to do this?. This is the web API method I want to call
// PUT api/MyObject/id
public IHttpActionResult PutMyObject(int id, MyObject myObject)
{
//Use param id to get the required object to edit
}
This is my code which does a Get:
public void GetMyObjectItems(Action<MyObject> success, Action<Exception> error)
{
var url = "http://address/api/MyObject";
var request = (HttpWebRequest)WebRequest.Create(url);
try
{
request.BeginGetResponse(result => ProcessResponse(success, error, request, result), null);
}
catch (Exception exception)
{
error(exception);
}
}
private void ProcessResponse(Action<MyObject> success, Action<Exception> error, HttpWebRequest request, IAsyncResult result)
{
try
{
var response = request.EndGetResponse(result);
//var locationList = response.Content.ReadAsAsync<MyObject>().Result;
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
var text = reader.ReadToEnd();
var list = _jsonConverter.DeserializeObject<MyObject>(text);
success(list);
}
}
catch (Exception exception)
{
error(exception);
}
}