public static async Task <Int32?> ConnectEleve(String _Email = null, String _Password = null) { var _Client = new HttpClient(); _Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8"); ElevesSearchParameters _Parameters = new ElevesSearchParameters(); _Parameters.Email = _Email; _Parameters.Password = _Password; HttpContent _JsonRequestContent = new StringContent(_Parameters.ToSerializedJson(), Encoding.UTF8, "application/json"); HttpRequestMessage _Request = new HttpRequestMessage { RequestUri = new Uri(Constants.WS_URL + "/Eleves/ConnectEleve"), Method = HttpMethod.Post, Headers = { { "APIKey", Constants.WS_PASSKEY } }, Content = _JsonRequestContent }; HttpResponseMessage _Response = _Client.SendAsync(_Request).Result; String _JsonResponseContent = await _Response.Content.ReadAsStringAsync(); Int32?_Id = JsonConvert.DeserializeObject <Int32?>(_JsonResponseContent); return(_Id); }
public static async Task <Eleve> GetEleve(Int32?_Id) { var _Client = new HttpClient(); _Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8"); ElevesSearchParameters _Parameters = new ElevesSearchParameters(); _Parameters.Id = _Id; HttpContent _JsonRequestContent = new StringContent(_Parameters.ToSerializedJson(), Encoding.UTF8, "application/json"); HttpRequestMessage _Request = new HttpRequestMessage { RequestUri = new Uri(Constants.WS_URL + "/Eleves/GetEleves"), Method = HttpMethod.Post, Headers = { { "APIKey", Constants.WS_PASSKEY } }, Content = _JsonRequestContent }; HttpResponseMessage _Response = _Client.SendAsync(_Request).Result; String _JsonResponseContent = await _Response.Content.ReadAsStringAsync(); List <Eleve> _Eleves = JsonConvert.DeserializeObject <List <Eleve> >(_JsonResponseContent); Eleve _Eleve = new Eleve(); if (_Eleves.Count > 0) { _Eleve = _Eleves[0]; } return(_Eleve); }