public async Task UpdateVehicleListAsync() { this.IsBusy = true; try { if (!_reachability.IsConnected()) { _toast.Show("No internet connection!"); } else { var vehicleViews = await _gatewayService.GetVehicleViewsAsync(); var vehicleViewVehicles = new Dictionary <string, IEnumerable <Models.BaseVehicle> >(vehicleViews.Count()); foreach (var vehicleView in vehicleViews) { vehicleViewVehicles.Add(vehicleView.Title, await _gatewayService.GetVehiclesAsync(vehicleView.Title)); } var vehiclesAndTrailers = vehicleViewVehicles.SelectMany(vvv => vvv.Value).DistinctBy(v => v.ID); var vehicles = vehiclesAndTrailers.Where(bv => !bv.IsTrailer).Select(bv => new Models.Vehicle(bv)); if (vehicles != null) { await _vehicleRepository.DeleteAllAsync(); try { await _vehicleRepository.InsertAsync(vehicles); } catch (Exception ex) { MvxTrace.Error("\"{0}\" in {1}.{2}\n{3}", ex.Message, "VehicleRepository", "InsertAsync", ex.StackTrace); throw; } Vehicles = _originalVehicleList = await _vehicleRepository.GetAllAsync(); //Recalls the filter text if there is text in the search field. if (VehicleSearchText != null) { this.FilterList(); } } } await UpdateSafetyProfilesAsync(); } finally { this.IsBusy = false; } }
// returns false if the customer code is not known // throws exceptions if the web services or db inserts fail private async Task <bool> SetupDeviceAsync() { if (!await _gatewayService.CreateDeviceAsync()) { _errorMessage = _unexpectedErrorMessage; return(false); } var device = await _gatewayService.GetDeviceAsync(CustomerCode); if (device == null) { _errorMessage = "The customer passcode you submitted doesn't exist, check the passcode and try again."; return(false); } var config = await _gatewayService.GetConfigAsync(); var applicationProfile = await _gatewayService.GetApplicationProfileAsync(); var drivers = await _gatewayService.GetDriversAsync(); var vehicleViews = await _gatewayService.GetVehicleViewsAsync(); var safetyProfiles = await _gatewayService.GetSafetyProfilesAsync(); var vehicleViewVehicles = new Dictionary <string, IEnumerable <Models.BaseVehicle> >(vehicleViews.Count()); foreach (var vehicleView in vehicleViews) { vehicleViewVehicles.Add(vehicleView.Title, await _gatewayService.GetVehiclesAsync(vehicleView.Title)); } var vehiclesAndTrailers = vehicleViewVehicles.SelectMany(vvv => vvv.Value).DistinctBy(v => v.ID); var vehicles = vehiclesAndTrailers.Where(bv => !bv.IsTrailer).Select(bv => new Models.Vehicle(bv)); var trailers = vehiclesAndTrailers.Where(bv => bv.IsTrailer).Select(bv => new Models.Trailer(bv)); //TODO: I'm not sure whether verb profiles will be used anywhere within this app, or whether this is a hangover from the Tough Touch implementation? If not used on completion of the project then remove from here and local db. // TODO: Get verb profile titles from config or somewhere? var verbProfileTitles = new[] { "Palletforce", "Cancel", "Complete", "Suspend" }; var verbProfiles = new List <Models.VerbProfile>(verbProfileTitles.Count()); foreach (var verbProfileTitle in verbProfileTitles) { var verbProfile = await _gatewayService.GetVerbProfileAsync(verbProfileTitle); if (verbProfile != null) { verbProfiles.Add(verbProfile); } } await _dataService.RunInTransactionAsync(c => { //TODO: Store the customer title? Need to get the customer title from somewhere. _customerRepository.Insert(new Customer() { ID = Guid.NewGuid(), CustomerCode = CustomerCode }, c); _deviceRepository.Insert(device, c); _verbProfileRepository.Insert(verbProfiles, c); _applicationProfileRepository.Insert(applicationProfile, c); _driverRepository.Insert(drivers, c); //TODO: relate Vehicles to VehicleViews? Are VehicleViews actually used for anything within the app? _vehicleRepository.Insert(vehicles, c); _trailerRepository.Insert(trailers, c); _safetyProfileRepository.Insert(safetyProfiles, c); _configRepository.Insert(config, c); }); //TODO: call fwRegisterDevice - what does this actually do? return(true); }