Exemple #1
0
        private void HandleLoadData(ArtistAlbumModel model)
        {
            var itemViewModels = model.Topalbums.Album
                                 .Select(x => new ArtistAlbumsItemViewModel(x.Name, x.Playcount, x.Image))
                                 .ToList();

            UpdateArtistsItemCollection(itemViewModels);

            SaveDataToLocalStorage();
        }
        public void SaveArtistAlbumData(ArtistAlbumModel model)
        {
            var items = model.Topalbums.Album
                        .Select(x => new ArtistAlbumsLocalModel(x.Name, x.Playcount, x.Image))
                        .ToList();

            _realm.Write(() =>
            {
                foreach (var item in items)
                {
                    var localModel = _realm.Add(item, false);
                }
            });
        }
        public async Task <ArtistAlbumModel> GetTopArtistAlbumsAsync(string name)
        {
            var url = $"https://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&artist={name}&api_key=fa91b7067617e8017f1daf354e2fb45e&format=json";

            try
            {
                var response = await _httpClient.GetStringAsync(new Uri(url));

                var result = ArtistAlbumModel.FromJson(response);

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }