private void SaveRoute(TripItinerary routeToSave) { var route = new FavoriteRoute { FontIconGlyph = FontIconGlyphs.FilledStar, Id = Guid.NewGuid(), IconFontFace = Constants.SegoeMdl2FontName, IconFontSize = Constants.SymbolFontSize, UserChosenName = $"{routeToSave.StartingPlaceName} → {routeToSave.EndingPlaceName}", }; TripLeg startPlace = routeToSave.ItineraryLegs.First(); TripLeg endPlace = routeToSave.ItineraryLegs.Last(); var places = new List <SimpleFavoritePlace>(); places.Add(new SimpleFavoritePlace { Lat = startPlace.StartCoords.Latitude, Lon = startPlace.StartCoords.Longitude, Name = routeToSave.StartingPlaceName, Type = ModelEnums.PlaceType.FavoritePlace }); places.Add(new SimpleFavoritePlace { Lat = endPlace.EndCoords.Latitude, Lon = endPlace.EndCoords.Longitude, Name = routeToSave.EndingPlaceName, Type = ModelEnums.PlaceType.FavoritePlace }); route.RoutePlaces = places; route.RouteGeometryStrings = routeToSave.RouteGeometryStrings.ToList(); _favoritesService.AddFavorite(route); }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (_dialogType == AddOrEditDialogType.Edit) { if (_favoritePlace != null) { ResultFavorite = new FavoritePlace { Confidence = null, Id = _favoritePlace.Id, FontIconGlyph = PossibleIconsList[SelectedIconIndex].Glyph, IconFontFace = PossibleIconsList[SelectedIconIndex].FontFamily.Source, IconFontSize = PossibleIconsList[SelectedIconIndex].FontSize, StringId = null, Lat = _favoritePlace.Lat, Lon = _favoritePlace.Lon, Name = _favoritePlace.Name, UserChosenName = NameText, Type = ModelEnums.PlaceType.FavoritePlace }; } else if (FavoriteRoute != null) { ResultFavorite = new FavoriteRoute { Id = FavoriteRoute.Id, FontIconGlyph = PossibleIconsList[SelectedIconIndex].Glyph, IconFontFace = PossibleIconsList[SelectedIconIndex].FontFamily.Source, IconFontSize = PossibleIconsList[SelectedIconIndex].FontSize, RouteGeometryStrings = FavoriteRoute.RouteGeometryStrings, RoutePlaces = FavoriteRoute.RoutePlaces, UserChosenName = NameText }; } } else if (_dialogType == AddOrEditDialogType.Add) { ResultFavorite = new FavoritePlace { Confidence = null, Id = Guid.NewGuid(), FontIconGlyph = PossibleIconsList[SelectedIconIndex].Glyph, IconFontFace = PossibleIconsList[SelectedIconIndex].FontFamily.Source, IconFontSize = PossibleIconsList[SelectedIconIndex].FontSize, StringId = null, Lat = SearchBoxPlace.Lat, Lon = SearchBoxPlace.Lon, Name = SearchBoxPlace.Name, UserChosenName = NameText, Type = ModelEnums.PlaceType.FavoritePlace, }; } this.Hide(); }
private async Task LoadRoutes() { RoutesFolder = await ApplicationData.Current.RoamingFolder.CreateFolderAsync("Routes", CreationCollisionOption.OpenIfExists); IReadOnlyList <StorageFolder> collections = await RoutesFolder.GetFoldersAsync(); // Empty the existing list library.Items[RoutesIndex].Items.Clear(); filteredLibrary.Items[RoutesIndex].Items.Clear(); foreach (StorageFolder collection in collections) { try { Collection <object> col = new Collection <object>(collection.DisplayName, "SolidStar"); var RouteFiles = await collection.GetFilesAsync(); foreach (StorageFile file in RouteFiles) { FavoriteRoute fav = await new FavoriteRoute().LoadFromFile(file); fav.Collection = collection.DisplayName; col.Items.Add(fav); } library.Items[RoutesIndex].Items.Add(col); } catch (Exception e) { throw e; } } // And the unsorted ones try { Collection <object> col = new Collection <object>("Unsortiert", "OutlineStar"); var RouteFiles = await RoutesFolder.GetFilesAsync(); foreach (StorageFile file in RouteFiles) { col.Items.Add(await new FavoriteRoute().LoadFromFile(file)); } library.Items[RoutesIndex].Items.Add(col); } catch (Exception e) { throw e; } }
private async void Accept(object sender, RoutedEventArgs e) { if (!Creatable) { return; } FavoriteRoute favorite = new FavoriteRoute() { Name = route.Name, Description = route.Description, Downhill = route.Downhill, Uphill = route.Uphill, Track = route.Track, Distance = route.Distance, BoundingBox = route.BoundingBox, StartPoint = route.StartPoint, Collection = collection, Symbol = route.Symbol, Timestamp = DateTime.Now }; // Its a new collection name, delete it from the old folder ... if (route is FavoriteRoute && collection != collectionBuffer) { await(route as FavoriteRoute).Delete(); } // ... and create a new Favorite in the right collection folder await favorite.SaveToFile(collection); // Set this as the new location Route = favorite; // Reset the Buffer routeBuffer = route; // Recreate the CommandBar CreateAppBarButtons(); //VisualStateManager.GoToState(this, "Default", true); // Because we added a State with an OnGoBackAction for this NavigationManager.Current.NavigateBack(); }
private void PinnedFavoriteClicked(IFavorite favorite) { FavoritePlace place = favorite as FavoritePlace; if (place != null) { ToPlace = place; } FavoriteRoute route = favorite as FavoriteRoute; if (route != null) { FromPlace = route.RoutePlaces.First(); ToPlace = route.RoutePlaces.Last(); } if (PlanTripCommand.CanExecute(null)) { PlanTrip(); } }
public void AddFavorite(FavoriteRoute favoriteRoute) => _connection.Insert(favoriteRoute);