1
I need to do an update of mine App. I’m having some doubts to pass the proper parameters to the URL of the service and perform the PUT. The service is working, testing by Postman, I can perform the Update, so just missing by App. My difficulty lies in the passage of From the button event for the method and in the method object that I will assemble. Here is the event of the button click
private async void Aprovar(object sender, EventArgs e)
{
string motivo = ent.Text;
await dataService.UpdateProdutoAsync(??????, motivo);
}
The reason is correct. The other parameter is Marking. I have it somewhere, maybe in var _date, but the whole issue is in mine dataService, as 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");
}
}
In the Jasonconvertobject is where the doubt lies. Assemble the object, if I’m passing primitive types only. I must pass the object Release, because in the service it represents an entity of the comic book, but I do not have it in this context, I have it before that screen, that it is passed by a GET.
EDIT1
I tried some solutions but still giving error: Here are the solutions tried. On the call screen of the Service, I have only items. Well, then I passed by the builder of this class the object Release. And at that point, I pass as a parameter to the method. It comes filled correctly, but is giving an untreated 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 liberates which is the object I pass by the constructor of the class of Items
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 code above is the click of the button, where I pick up the Release correct and step to the 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 report that there is information and it is correct
And this is Service, that is giving error. This is the Screenshot of the error:
EDIT2
I put a Try.. catch and picked up this message:
At Authorizer.Service.Dataservice+d__4.Movenext () [0x00152] in C: Mobile Authorizing Authorizing Authorizing Service Dataservice.Cs:62
What can make this mistake?
EDIT3
I’m pretty sure the problem is in the var date. She receives an object of the type Release and this object within my App, not exactly the same as the object within the service. This GET works, but the Get is already formatted the service and when receiving in the App, is already done the CAST for the guys who App will use. However, no PUT is different, the way is reverse, I pass the APP for the service and I think this is making this mistake.