public static async Task<IEnumerable<HelpRequestModel>> GetNearRequests( CoordinatesModel coordinates, int maxDistance, string sessionKey) { headers[sessionHeaderName] = sessionKey; string url = baseUrl + "near/" + maxDistance.ToString(); return await HttpRequester.Post<IEnumerable<HelpRequestModel>>(url, coordinates, headers); }
private async void HandleFilterRequests(object obj) { if(string.IsNullOrEmpty(MaxDistance)) { return; } int maxDistance; if(!int.TryParse(MaxDistance, out maxDistance)) { ErrorMessage = "Invalid distance"; return; } ErrorMessage = ""; try { var geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; var position = await geolocator.GetGeopositionAsync(); var coordinates = new CoordinatesModel() { Latitude = position.Coordinate.Latitude, Longitude = position.Coordinate.Longitude }; HelpRequests = await HelpRequestsPersister.GetNearRequests( coordinates, maxDistance, AccountManager.CurrentUser.SessionKey); OnPropertyChanged("HelpRequests"); } catch (Exception ex) { ErrorMessage = "Unable to get current location"; } }
private async void HandleAddRequest(object obj) { try { if(string.IsNullOrEmpty(Title) || string.IsNullOrWhiteSpace(Title)) { ErrorMessage = "Enter a request title"; return; } if (string.IsNullOrEmpty(Text) || string.IsNullOrWhiteSpace(Text)) { ErrorMessage = "Enter a request text"; return; } var geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; var position = await geolocator.GetGeopositionAsync(); var coordinates = new CoordinatesModel() { Latitude = position.Coordinate.Latitude, Longitude = position.Coordinate.Longitude }; var request = new HelpRequestModel() { Title = Title, Text = Text, PictureUrl = PictureUrl, Coordinates = coordinates }; IsAddingRequest = true; OnPropertyChanged("IsAddingRequest"); await HelpRequestsPersister.AddRequest(request, AccountManager.CurrentUser.SessionKey); NavigationService.Navigate(ViewType.MyRequests); NotificationsManager.ShowToastNotification("Request added"); } catch (Exception ex) { ErrorMessage = "Unable to get location"; IsAddingRequest = false; OnPropertyChanged("IsAddingRequest"); } }