public async Task <WebResult> SendPosition(string token, Position position, string address, double?accuracy) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Constants.BaseUrl); var parameters = new Dictionary <string, string> { ["token"] = token, ["latitude"] = position.Latitude.ToString(CultureInfo.InvariantCulture), ["longitude"] = position.Longitude.ToString(CultureInfo.InvariantCulture), ["address"] = address, ["accuracy"] = accuracy?.ToString(CultureInfo.InvariantCulture) }; var response = await client.PostAsync(Constants.SendPositionSubUrl, new FormUrlEncodedContent(parameters)); return(response.IsSuccessStatusCode ? WebResult.Success() : WebResult.Error($"Error: {response.StatusCode}")); } } catch (Exception) { return(WebResult.Error(AppResources.ErrorSendingPosition)); } }
public async Task <WebResult> StopSession(string privateToken) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(Constants.BaseUrl); var response = await client.DeleteAsync($"{Constants.TokenSubUrl}/{privateToken}"); Debug.WriteLine($"Stop session result: {response.StatusCode} {response.RequestMessage.RequestUri}"); return(response.IsSuccessStatusCode ? WebResult.Success() : WebResult.Error($"{AppResources.Error}: {response.StatusCode}")); } } catch (Exception) { return(WebResult.Error(AppResources.CannotStopTrackingNoInternet)); } }