public async Task Post(VehicleLocationModel locationData) { #region Control Flow Explanation /* * INSERT CONTROL FLOW * ------------------------------- * 1. Is Vehicle on database? * YES: Got the vehicleId? Proceed with inserting latest location * NO: Insert vehicle, get the Vehicle Id, Insert location * * 2. The end. * */ #endregion try { var _vehicalId = 0; var vehicle = await Task.Run(() => { return(_vehicleData.GetVehicle(locationData.UniqueVehicleName)); }); if (vehicle is null) { var insertedData = await Task.Run(() => { return(_vehicleData.InsertVehicle(new VehicleInsertModel() { Description = locationData.UniqueVehicleName })); }); _vehicalId = insertedData.Id; } else { _vehicalId = vehicle.Id; } _ = await Task.Run(() => { return(_vehicleData.InsertOrUpdateLocation(new VehicleLocationInsertModel() { VehicleId = _vehicalId, Longitude = locationData.Longitude, Latitude = locationData.Latitude })); }); } catch (Exception) { //Ignore for now } }
private void ZoomInOnLocation(VehicleLocationModel myLocation) { try { var mapSpan = MapSpan.FromCenterAndRadius (new Position(myLocation.Latitude, myLocation.Longitude), Distance.FromKilometers(0.1)); span = mapSpan; mapOnDevice.MoveToRegion(mapSpan); } catch (Exception ex) { _viewModel.ErrorMessage = ex.Message; } }
public async Task <bool> ReportVehicleLocation(VehicleLocationModel vehicleLocation) { Debug.WriteLine($"{DateTime.Now} - Location data downloading"); try { await ApiHelper.ApiClient.PostRequest("vehiclelocations", vehicleLocation) .ExecuteAsync(); return(true); } catch (Exception) { throw; } }
private void UpdateLocationDisplayText(VehicleLocationModel myLocation) { _viewModel.LocationDisplayText = $"{ myLocation.UniqueVehicleName} at: LAT: {myLocation.Latitude} LONG: {myLocation.Longitude}"; }