I need to update my App . I'm having some questions about passing the parameters to the URL of the service and running PUT . The service is working, testing by Postman, I can perform the Update, so it's only missing App . My difficulty is in passing the From button method to the method and the object method I'm going to mount . Here's the click button event
private async void Aprovar(object sender, EventArgs e)
{
string motivo = ent.Text;
await dataService.UpdateProdutoAsync(??????, motivo);
}
The reason is correct. The other parameter is the IdOrcamento. I have it somewhere, maybe in var _data , but the whole question is in my dataService below
public async Task UpdateProdutoAsync(int id, string value)
{
string url = $"http://meu_site/autorizador/api/itens/{id}/{value}";
var uri = new Uri(string.Format(url, id));
var data = JsonConvert.SerializeObject(??????);
var content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
response = await client.PutAsync(uri, content);
if (!response.IsSuccessStatusCode)
{
throw new Exception("Erro ao atualizar produto");
}
}
JasonConvertObject is where the doubt lies. Mount the object if only passing primitive types. I have to pass the Release object, because in the service it represents a DB entity, but I do not have it in this context, I have it before this screen, it is passed by a GET .
EDIT1
I've tried some solutions, but it keeps giving error: Here are the tried solutions. On the Service call screen, I have only items . Well, then I passed the Release constructor of this class. And at that point, I pass as a parameter to the method. It comes filled correctly but is giving an unhandled error, and the error says nothing. See the code as it was.
private async void btnItens_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new MainPageItens(_idorcamento, libera));
}
The code, I have frees which is the object that I pass through the constructor of the Items class
private async void Aprovar(object sender, EventArgs e)
{
string motivo = ent.Text;
List<ItensLib> lib = new List<ItensLib>();
lib = _data;
var lista = liber
.Where(l => l.IdOrcamento == IdOrcamento)
.ToList();
await dataService.UpdateProdutoAsync(IdOrcamento, motivo, lista);
}
The above code is the click of the button where I get the correct Release and step to method.
public async Task UpdateProdutoAsync(int id, string value, List<Liberacao> liber)
{
string url = $"http://www.inetglobal.com.br/autorizador/api/itens/{id}/{value}";
var uri = new Uri(string.Format(url, id));
var data = JsonConvert.SerializeObject(liber);
var content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
response = await client.PutAsync(uri, content);
if (!response.IsSuccessStatusCode)
{
throw new Exception("Erro ao atualizar produto");
}
}
See in this sreenshot that there is information and is correct
AndthisisService,whichisgivingerror.ThisistheErrorScreenshot:
EDIT2
I put a try..catch and got this message:
at Authorizer.Service.DataService + d__4.MoveNext () [0x00152] in C: \ Mobile \ Authorizer \ Authorizer \ Authorizer \ Service \ DataService.cs: 62
What can give this error?
EDIT3
I'm pretty sure the problem is in var date . It receives an object of type Release and this object within my App, not exactly equal to the object within the service. This in GET works, but Get already comes formatted from the service and when receiving in the App, is already done the CAST for the types that App will use. But in PUT it is different, the path is the other way around, I step from the APP to the service and I think this is making this error. / p>