Hello,
It is my first code in xamarin and I want to just save the data using web api but I am unable to do so after hours of hardwork. Can anybody help to identify the error.
` [HttpPost]
public string CreateEmpAttandance(string value)
{
// Check if emp code not exist then response send that wrong emp code
if (value != "1234")
{
string json = @{ data: 'Emp Code is not valid.'};
var jObject = JObject.Parse(json);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(jObject.ToString(), System.Text.Encoding.UTF8, "application/json");
return response;
}
else
{
string json = @"{ data: 'data save sucessfully.'}";
var jObject = JObject.Parse(json);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(jObject.ToString(), System.Text.Encoding.UTF8, "application/json");
return response;
}
}`
here is my web api method.
my calling function is
`public async Task SaveTodoItemAsync(string EmpCode)
{
try
{
string url = "http://192.168.1.9/attandanceapi/api/attandance/";
var uri = new Uri(string.Format(url));
var json = JsonConvert.SerializeObject(EmpCode);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
response = await client.PutAsync(url, content);
var responses = response;
}
catch (Exception ex)
{
var w = ex.ToString();
}
}`