public async Task <IActionResult> Watchlist([FromServices] IRepositoryUser repoUser)
        {
            List <WatchlistItems> searchedSymbols = new List <WatchlistItems>();
            var watchlist = repoUser.RetrieveUserWatchlist();
            var symbols   = watchlist.Split(';');

            foreach (string sym in symbols)
            {
                var reqUri = "https://" + $@"www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=" + sym + "&apikey=" + _apiKey;
                using (var httpClient = new HttpClient())
                {
                    using (var response = await httpClient.GetAsync(reqUri))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        dynamic        data       = JsonConvert.DeserializeObject(apiResponse);
                        var            count      = data.bestMatches.Count;
                        var            firstMatch = data.bestMatches[0];
                        WatchlistItems wl         = (JsonConvert.DeserializeObject <WatchlistItems>(firstMatch.ToString()));
                        searchedSymbols.Add(wl);
                    }
                }
            }
            return(View(searchedSymbols));
            //return View(model);
        }
Ejemplo n.º 2
0
        private void WatchlistService_WatchlistChanged(object sender, MediaItem item)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                if (WatchlistItems == null)
                {
                    return;
                }

                if (item.IsFavourite && !WatchlistItems.Any(x => x.Id == item.Id))
                {
                    WatchlistItems.Add(item);
                }
                else
                {
                    var toRemove = WatchlistItems.FirstOrDefault(x => x.Id == item.Id);
                    WatchlistItems.Remove(toRemove);
                }
            });
        }