private void PopulateAlbumArtistDetails() { ArtistName = string.Empty; var albumArtist = Artist?.Name == AddNew ? null : Artist; ArtistName = albumArtist?.Name ?? string.Empty; Albums = albumArtist == null ? new List <Album>() : Artist.Albums .OrderBy(a => a.Title) .ToList(); Albums.Insert(0, new Album { Title = AddNew, Artist = albumArtist }); if (Albums.Count == 1) { Album = Albums.First(); } PopulateAlbumDetails(); }
private async void AddNewAlbum() { var album = new VkPlaylist() { Title = "New album" }; var flyout = new FlyoutControl(); flyout.FlyoutContent = new EditAlbumView(album); var result = await flyout.ShowAsync(); if ((bool)result) { try { var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(album.Title); if (newAlbumId != 0) { album.Id = newAlbumId; album.OwnerId = ViewModelLocator.Vkontakte.AccessToken.UserId; Albums.Insert(5, album); } } catch (Exception ex) { LoggingService.Log(ex); } } }
private async Task GetAlbumResults(string searchPhrase) { var albums = await _dataService.GetAlbumSearchResults(searchPhrase, 0, 4); if (albums.Length == 0) { HasAlbums = false; } else { HasAlbums = true; HasMoreAlbums = albums.Length > 3; var index = 0; var newResults = albums.Take(3).Reverse(); foreach (var item in newResults) { Albums.Insert(index, new GridPanel { Title = item.Title, SubTitle = item.Artist.Name, ImageSource = _dataService.GetImage(item.AlbumId, true)?.AbsoluteUri, Data = item }); index++; } if (Albums.Count > newResults.Count()) { var c = Albums.Count; for (int i = c - 1; i >= newResults.Count(); i--) { Albums.RemoveAt(i); } } } }
void XtraSetIndexAlbumsItem(XtraSetItemIndexEventArgs e) { Albums.Insert(e.NewIndex, (AlbumData)e.Item.Value); }
private void Migrate() { CreateTable("Album", c => new { AlbumId = c.Column <int>(primaryKey: true), Title = c.Column <string>(nullable: false), ArtistId = c.Column <int>() }, t => new { FK = t.ForeignKey(a => a.ArtistId, "Artist", "ArtistId") }); CreateTable("Artist", c => new { ArtistId = c.Column <int>(primaryKey: true), Name = c.Column <string>(nullable: false) }); CreateTable("Customer", c => new { CustomerId = c.Column <int>(primaryKey: true), FirstName = c.Column <string>(nullable: false), LastName = c.Column <string>(nullable: false), Company = c.Column <string>(), Address = c.Column <string>(), City = c.Column <string>(), State = c.Column <string>(), Country = c.Column <string>(), PostalCode = c.Column <string>(), Phone = c.Column <string>(), Fax = c.Column <string>(), Email = c.Column <string>(nullable: false), SupportRepId = c.Column <int?>() }, t => new { FK = t.ForeignKey(c => c.SupportRepId, "Employee", "EmployeeId") }); CreateTable("Employee", c => new { EmployeeId = c.Column <int>(primaryKey: true), FirstName = c.Column <string>(nullable: false), LastName = c.Column <string>(nullable: false), Title = c.Column <string>(), ReportsTo = c.Column <int>(), BirthDate = c.Column <DateTime?>(), HireDate = c.Column <DateTime?>(), Address = c.Column <string>(), City = c.Column <string>(), State = c.Column <string>(), Country = c.Column <string>(), PostalCode = c.Column <string>(), Phone = c.Column <string>(), Fax = c.Column <string>(), Email = c.Column <string>(nullable: false) }, t => new { FK = t.ForeignKey(c => c.ReportsTo, "Employee", "EmployeeId") }); CreateTable("Genre", c => new { GenreId = c.Column <int>(primaryKey: true), Name = c.Column <string>() }); CreateTable("Invoice", c => new { InvoiceId = c.Column <int>(primaryKey: true), CustomerId = c.Column <int>(), InvoiceDate = c.Column <DateTime>(), BillingAddress = c.Column <string>(), BillingCity = c.Column <string>(), BillingState = c.Column <string>(), BillingCountry = c.Column <string>(), BillingPostalCode = c.Column <string>(), Total = c.Column <decimal>() }, t => new { FK = t.ForeignKey(c => c.CustomerId, "Customer", "CustomerId") }); CreateTable("InvoiceLine", c => new { InvoiceLineId = c.Column <int>(primaryKey: true), InvoiceId = c.Column <int>(), TrackId = c.Column <int>(), UnitPrice = c.Column <decimal>(), Quantity = c.Column <int>() }, t => new { FK_Invoice = t.ForeignKey(i => i.InvoiceId, "Invoice", "InvoiceId"), FK_Track = t.ForeignKey(i => i.TrackId, "Track", "TrackId") }); CreateTable("MediaType", c => new { MediaTypeId = c.Column <int>(primaryKey: true), Name = c.Column <string>() }); CreateTable("Playlist", c => new { PlaylistId = c.Column <int>(primaryKey: true), Name = c.Column <string>() }); CreateTable("PlaylistTrack", c => new { PlaylistId = c.Column <int>(), TrackId = c.Column <int>() }, t => new { FK_Playlist = t.ForeignKey(pt => pt.PlaylistId, "Playlist", "PlaylistId"), FK_Track = t.ForeignKey(pt => pt.TrackId, "Track", "TrackId") }); CreateTable("Track", c => new { TrackId = c.Column <int>(primaryKey: true), Name = c.Column <string>(nullable: false), AlbumId = c.Column <int?>(), MediaTypeId = c.Column <int>(), GenreId = c.Column <int?>(), Composer = c.Column <string>(), Milliseconds = c.Column <int>(), Bytes = c.Column <int?>(), UnitPrice = c.Column <decimal>() }, t => new { FK_Album = t.ForeignKey(c => c.AlbumId, "Album", "AlbumId"), FK_MediaType = t.ForeignKey(c => c.MediaTypeId, "MediaType", "MediaTypeId"), FK_Genre = t.ForeignKey(c => c.GenreId, "Genre", "GenreId") }); CreateView("AlbumView", Albums.GroupJoin(Tracks, album => album.AlbumId, track => track.AlbumId, (album, tracks) => new { AlbumId = album.AlbumId, Title = album.Title, ArtistId = album.ArtistId, TotalPrice = tracks.Sum(t => t.UnitPrice), TrackCount = tracks.Count() })); CreateIndex <Track>("Track_AlbumId", false, t => t.AlbumId); Albums.Insert(new Album { ArtistId = 2, Title = "Something" }); }
public async Task AddSongAsync(Song song, string artworkUrl) { if (Songs.Count(p => p.ProviderId == song.ProviderId) > 0) { throw new Exception("AlreadySavedToast".FromLanguageResource()); } #region create artist if (song.Artist.ProviderId == "lastid.") { song.Artist.ProviderId = "autc.single." + song.ProviderId; } var artist = Artists.FirstOrDefault(entry => entry.ProviderId == song.Artist.ProviderId); if (artist == null) { await _sqlService.InsertAsync(song.Artist); if (song.Album != null) { song.Album.PrimaryArtistId = song.Artist.Id; } Artists.Insert(0, song.Artist); } else { song.Artist = artist; if (song.Album != null) { song.Album.PrimaryArtistId = artist.Id; } } song.ArtistId = song.Artist.Id; #endregion #region create album if (song.Album == null) { song.Album = new Album { PrimaryArtistId = song.ArtistId, Name = song.Name + " (Single)", PrimaryArtist = song.Artist, ProviderId = "autc.single." + song.ProviderId }; await _sqlService.InsertAsync(song.Album); Albums.Insert(0, song.Album); song.Artist.Albums.Insert(0, song.Album); } else { var album = Albums.FirstOrDefault(p => p.ProviderId == song.Album.ProviderId); if (album != null) { song.Album = album; } else { await _sqlService.InsertAsync(song.Album); Albums.Insert(0, song.Album); song.Artist.Albums.Insert(0, song.Album); } } song.AlbumId = song.Album.Id; #endregion #region Download artwork if (artworkUrl != null) { //Use the album if one is available var filePath = string.Format(CollectionConstant.ArtworkPath, song.Album.Id); //Check if the album artwork has already been downloaded var artworkExists = await StorageHelper.FileExistsAsync(filePath); if (!artworkExists) { try { using (var client = new HttpClient()) { using (var stream = await client.GetStreamAsync(artworkUrl)) { using ( var fileStream = await (await StorageHelper.CreateFileAsync(filePath)).OpenStreamForWriteAsync() ) { await stream.CopyToAsync(fileStream); //now set it song.Album.Artwork = new BitmapImage(new Uri(CollectionConstant.LocalStorageAppPath + filePath)); } } } } catch (Exception e) { Debug.WriteLine("Some shit happened saving the artwork, here: " + e); } } } if (song.Album.Artwork == null) { song.Album.Artwork = CollectionConstant.MissingArtworkImage; } #endregion //Insert to db await _sqlService.InsertAsync(song); song.Artist.Songs.Insert(0, song); song.Album.Songs.Insert(0, song); Songs.Insert(0, song); }