/// <summary> /// Maps the Album returned from the Domain Model, to the AlbumModel of the UI /// </summary> /// <param name="albums">Domain Albums collection</param> /// <returns>AlbumModel collection</returns> private List<AlbumModel> MapAlbumsToAlbumModels(IEnumerable<Album> albums) { // The viewmodel collection var albumsViewModel = new List<AlbumModel>(); // Map the albums to the AlbumViewModel foreach (var a in albums) { var mappedAlbum = new AlbumModel(); //OK to New, UI model only, no injection needed. // Map the album specific data mappedAlbum.Id = a.Id.ToString(); // No localisation needed here, it's won't be actually displayed. mappedAlbum.Title = a.Title; mappedAlbum .RawReleased = a.Released; // Update the DateFormate property. mappedAlbum.ArtistName = a.Artist.Name; // Load the large and medium images only. var largeImage = a.Images.FirstOrDefault(i => i.Size == ImageSizeEnum.large); if (largeImage != null) mappedAlbum.SetImageLarge(largeImage.Url); else mappedAlbum.SetImageLarge(@"Assets\MediumGray.png"); var mediumImage = a.Images.FirstOrDefault(i => i.Size == ImageSizeEnum.medium); if (mediumImage != null) mappedAlbum.SetImageMedium(mediumImage.Url); else mappedAlbum.SetImageMedium(@"Assets\LightGray.png"); // Map the LastFM stuff. mappedAlbum.LastFMUrl = a.Url; mappedAlbum.LastFMMbid = a.Mbid; // Map the Wiki stuff mappedAlbum.Wiki = new WikiModel(); mappedAlbum.Wiki.Summary = a.Wiki.Summary; mappedAlbum.Wiki.Content = a.Wiki.Content; mappedAlbum.Wiki.RawPublished = a.Wiki.Published; // Set the DateTime property // Map the Genres. mappedAlbum.Genres = new List<GenreModel>(); foreach (var g in a.Genres) { var mappedGenre = new GenreModel() { Id = g.Id.ToString(), Name = g.Name, LastFMUrl = g.Url }; mappedAlbum.Genres.Add(mappedGenre); } // Map the tracks mappedAlbum.Tracks = new List<TrackModel>(); foreach (var tr in a.Tracks) { var mappedTrack = new TrackModel() { Id = tr.Id.ToString(), Number = tr.Number.ToString(), // No localisation here, there are unlikely to be more than 99 tracks. Title = tr.Title, RawDuration = tr.Duration, // set the TimeSpan property, not the localised display property LastFMMbid = tr.Mbid, LastFMUrl = tr.Url, MediaFilePath = tr.mediaFilePath }; mappedAlbum.Tracks.Add(mappedTrack); } // Add to the ViewModel albumsViewModel.Add(mappedAlbum); } return albumsViewModel; }
/// <summary> /// Create the mock genres /// </summary> /// <returns>mock genres</returns> private static List<GenreModel> CreateDarkSideOfTheMoonGenres() { var darkSideGenres = new List<GenreModel>(); var rock = new GenreModel(); rock.Id = "1"; rock.Name = "Rock"; rock.LastFMUrl = string.Empty; darkSideGenres.Add(rock); var seventies = new GenreModel(); seventies.Id = "2"; seventies.Name = "70's"; seventies.LastFMUrl = string.Empty; darkSideGenres.Add(seventies); var concept = new GenreModel(); concept.Id = "3"; concept.Name = "Concept"; concept.LastFMUrl = string.Empty; darkSideGenres.Add(concept); return darkSideGenres; }
/// <summary> /// Gets the album information from the LastFM album.getInfo service /// </summary> /// <param name="ArtistName">The Artist to search for</param> /// <param name="AlbumName">The Album to search for</param> /// <returns>The Album information as an AlbumModel class.</returns> public async Task<AlbumModel> GetLastFMAlbumInfoAsync(string ArtistName, string AlbumName) { // Call the LastFMService // Check, this will include the returned information for the Artist/Album combination. // It won't necessarily have all the information in it. Search again is the way round // that. var lfmAlbum = await _lastFMService.GetAlbumInfoAsync(AlbumName, ArtistName); // Map the album to the LastFMViewModel var mappedAlbum = new AlbumModel(); //OK to New, UI model only, no injection needed. // Map the album specific data mappedAlbum.Id = string.Empty; // No value for this yet. mappedAlbum.Title = lfmAlbum.name; // Release date DateTime lfmDate = new DateTime(); DateTime.TryParse(lfmAlbum.releasedDate, out lfmDate); mappedAlbum.RawReleased = lfmDate; // mappedAlbum.Released = LocalisationHelper.LocalisedDate(lfmDate); // Artist stuff mappedAlbum.ArtistName = lfmAlbum.artist.name; mappedAlbum.ArtistUrl = lfmAlbum.artist.url; mappedAlbum.ArtistMbid = lfmAlbum.artist.mbid; // Load the large and medium images only. var largeImage = lfmAlbum.images.FirstOrDefault(i => i.size == "large"); if (largeImage != null) mappedAlbum.SetImageLarge(largeImage.imageUrl); else mappedAlbum.SetImageLarge(@"Assets\MediumGray.png"); var mediumImage = lfmAlbum.images.FirstOrDefault(i => i.size == "medium"); if (mediumImage != null) mappedAlbum.SetImageMedium(mediumImage.imageUrl); else mappedAlbum.SetImageMedium(@"Assets\LightGray.png"); // Map the LastFM stuff. mappedAlbum.LastFMUrl = lfmAlbum.url; mappedAlbum.LastFMMbid = lfmAlbum.mbid; // Map the Wiki stuff mappedAlbum.Wiki = new WikiModel(); mappedAlbum.Wiki.Summary = lfmAlbum.wiki.summary; mappedAlbum.Wiki.Content = lfmAlbum.wiki.content; DateTime wikiDate = new DateTime(); DateTime.TryParse(lfmAlbum.wiki.published, out wikiDate); mappedAlbum.Wiki.RawPublished = wikiDate; //mappedAlbum.Wiki.Published = LocalisationHelper.LocalisedDate(wikiDate); // Map the Genres. mappedAlbum.Genres = new List<GenreModel>(); foreach (var g in lfmAlbum.tags) { var mappedGenre = new GenreModel() { Id = string.Empty, Name = g.name, LastFMUrl = g.url }; mappedAlbum.Genres.Add(mappedGenre); } // Map the tracks mappedAlbum.Tracks = new List<TrackModel>(); foreach (var tr in lfmAlbum.tracks) { var mappedTrack = new TrackModel() { Id = string.Empty, Number = tr.rank, Title = tr.name, LastFMMbid = tr.mbid, LastFMUrl = tr.url }; TimeSpan trackDuration = new TimeSpan(); int secs = 0; if (int.TryParse(tr.duration, out secs)) { trackDuration = TimeSpan.FromSeconds(secs); } //mappedTrack.Duration = LocalisationHelper.LocaliseDuration(trackDuration); mappedTrack.RawDuration = trackDuration; mappedAlbum.Tracks.Add(mappedTrack); } return mappedAlbum; }