Skip to content

Instantly share code, notes, and snippets.

@brunoportess
Created October 15, 2017 16:56
Show Gist options
  • Save brunoportess/18e712f8a30d5f55657902414e475936 to your computer and use it in GitHub Desktop.
Save brunoportess/18e712f8a30d5f55657902414e475936 to your computer and use it in GitHub Desktop.
//ESSA É A CONTROLLER DA API QUE RECEBE OS DADOS (ASPNET CORE)
[Produces("application/json")]
[Route("api/cupons/[action]")]
public class CuponsController : Controller
{
private readonly CupomDAO _cupomDao;
private readonly ClienteDAO _clienteDao;
public CuponsController(IConfiguration configuration)
{
_cupomDao = new CupomDAO(configuration);
_clienteDao = new ClienteDAO(configuration);
}
// POST: api/Cupons
[HttpPost]
public string VerificaCupom(string idParceiro, string codigo)
{
return codigo;
//return _cupomDao.CupomClienteParceiro(idParceiro, codigo);
}
}
//ESSE É O HTTPCLIENT DO APP QUE ENVIA OS DADOS
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Settings.RestAPISettings);
// Add string parameters
var content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("idParceiro", idParceiro),
new KeyValuePair<string, string>("codigo", codigo)
});
var result = await client.PostAsync("cupons/VerificaCupom/", content);
if (!result.IsSuccessStatusCode) return null;
var resultContent = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<Cupom>>(resultContent);
//Debug.WriteLine(resultContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment