/// <summary> /// Adds a new collection to the database. Everything is done in the viewmodel except the title, which /// is taken from the collectionTitle element. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { CollectionViewModel collection = new CollectionViewModel(); collection.Title = collectionTitle.Text; collection.AddCollection(collection); this.Frame.Navigate(typeof(ItemsPage)); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { // TODO: Create an appropriate data model for your problem domain to replace the sample data //var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter); CollectionViewModel ctx = new CollectionViewModel(); IList<CollectionViewModel> collectionList = ctx.GetAllCollections(); this.DefaultViewModel["Items"] = collectionList; }
public bool AddCollection(CollectionViewModel model) { try { using (var db = new SQLite.SQLiteConnection(app.DBPath)) { int success = db.Insert(new Collection() { Title = model.Title, DateCreated = DateTime.Now, Void = false }); if (success != 0) return true; } return false; } catch { return false; } }
public CollectionViewModel GetCollection(int collectionId) { CollectionViewModel collection = new CollectionViewModel(); using (var db = new SQLite.SQLiteConnection(app.DBPath)) { var _collection = (db.Table<Collection>().Where( c => c.Id == collectionId)).FirstOrDefault(); collection.Id = _collection.Id; collection.Title = _collection.Title; collection.DateCreated = _collection.DateCreated; collection.Void = _collection.Void; // GET ALBUMS var _albums = (db.Table<Album>().Where( c => c.CollectionId == collectionId)).ToList(); List<AlbumViewModel> albumList = new List<AlbumViewModel>(); foreach (var _album in _albums) { AlbumViewModel album = new AlbumViewModel(); album.Id = _album.Id; album.CollectionId = _album.CollectionId; album.Artist = _album.Artist; album.Title = _album.Title; album.LastFmId = _album.LastFmId; album.MusicBrainzId = _album.MusicBrainzId; album.DateAdded = _album.DateAdded; album.Void = _album.Void; albumList.Add(album); } collection.Albums = albumList; } return collection; }
/// <summary> /// Creates a popup with sort options for the detail page. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { // Create a new popup Popup popUp = new Popup(); popUp.IsLightDismissEnabled = true; // Create a new stack panel StackPanel panel = new StackPanel(); panel.Background = bottomAppBar.Background; panel.Height = 80; panel.Width = 180; // Create buttons to add to collections CollectionViewModel ctx = new CollectionViewModel(); // Returns list of collections IList<CollectionViewModel> collectionList = ctx.GetAllCollections(); // Iterates through each collection and creates a list - this could get messy if there are // a lot of collections. Look to creating a drop-down list foreach (var co in collectionList) { Button byAuthorButton = new Button(); byAuthorButton.Content = co.Title; byAuthorButton.Name = co.Id.ToString(); byAuthorButton.Style = (Style)App.Current.Resources["TextButtonStyle"]; byAuthorButton.Margin = new Thickness(20, 5, 20, 5); byAuthorButton.Click += SortButton_Click; panel.Children.Add(byAuthorButton); } popUp.Child = panel; popUp.HorizontalOffset = Window.Current.CoreWindow.Bounds.Right - panel.Width - 4; popUp.VerticalOffset = Window.Current.CoreWindow.Bounds.Bottom - bottomAppBar.ActualHeight - panel.Height - 4; popUp.IsOpen = true; }