Ejemplo n.º 1
0
        private async Task <List <FullFilm> > LoadFilmsFromFile(string fileName)
        {
            if (!await _storageService.FileExistsAsync(fileName))
            {
                return(new List <FullFilm>());
            }

            var json = await _storageService.ReadAllTextAsync(fileName);

            var filmList = JsonConvert.DeserializeObject <List <FullFilm> >(json);

            return(filmList?.OrderBy(x => x.Weight).ToList() ?? new List <FullFilm>());
        }
Ejemplo n.º 2
0
        private async Task <List <Cinema> > LoadCinemasFromFileOrApi()
        {
            if (!await _storageService.FileExistsAsync(CinemaCacheFile))
            {
                var cinemas = await _apiClient.GetCinemas();

                var json = JsonConvert.SerializeObject(cinemas);
                await _storageService.WriteAllTextAsync(CinemaCacheFile, json);

                return(cinemas);
            }

            var fileContents = await _storageService.ReadAllTextAsync(CinemaCacheFile);

            var cinemaList = JsonConvert.DeserializeObject <List <Cinema> >(fileContents);

            return(cinemaList ?? new List <Cinema>());
        }