Ejemplo n.º 1
0
        public async Task <ObservableCollection <Cinema> > GetCinemaRepertoires(string city)
        {
            ObservableCollection <Cinema> cinemas = _cacheService.Get <ObservableCollection <Cinema> >(city);

            if (cinemas == null || cinemas.Count == 0)
            {
                if (_connectivity.EnsureInternetAccess())
                {
                    var uri = ResourceIdentifier.CinemaRepertoiresUri(city);
                    try
                    {
                        var responseString = await _httpService.Get(uri);

                        cinemas = new ObservableCollection <Cinema>((List <Cinema>)_jsonConverter.DeserializeObject(responseString, typeof(List <Cinema>)));
                        _cacheService.Set(city, cinemas, CacheExpiry(15.0));
                    }
                    catch
                    {
                        ShowGetFailedNotification();
                        return(new ObservableCollection <Cinema>());
                    }
                }
                else
                {
                    ShowConnectionNotification();
                    return(new ObservableCollection <Cinema>());
                }
            }

            return(cinemas);
        }