Exemplo n.º 1
0
        public async Task <CinemaDetails> GetCinema(string name)
        {
            CinemaDetails cinema = _cacheService.Get <CinemaDetails>(name);

            if (cinema == null)
            {
                if (_connectivity.EnsureInternetAccess())
                {
                    var uri = ResourceIdentifier.CinemasUri();
                    try
                    {
                        var responseString = await _httpService.Get(uri);

                        var cinemas = (List <CinemaDetails>)_jsonConverter.DeserializeObject(responseString, typeof(List <CinemaDetails>));
                        var query   = (from c in cinemas where (c.Name + " " + c.City).Equals(name) select c);
                        cinema = query.First();
                        _cacheService.Set(name, cinema, CacheExpiry(15.0));
                    }
                    catch
                    {
                        ShowGetFailedNotification();
                        return(new CinemaDetails());
                    }
                }
                else
                {
                    ShowConnectionNotification();
                    return(new CinemaDetails());
                }
            }

            return(cinema);
        }