Exemplo n.º 1
0
        public ListSamplesPageViewModel(INavigation navigationService)
        {
            NavigationService = navigationService;
            ClearCommand      = new Command(ClearCommandExecute, ClearCommandCanExecute);
            SelectionCommand  = new Command(SelectionCommandExecute);

            LoadSamples();
            MyTitre = $"Liste des Saamples";

            using (var db = new KaamelottDB())
            {
                db.Database.EnsureCreated();
            }
        }
Exemplo n.º 2
0
        private void LoadSamples()
        {
            IsBusy = true;
            Task.Factory.StartNew(async() =>
            {
                //Si on a internet, on synchronise (Api -> DB)
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    KaamelottAPI api = new KaamelottAPI();
                    var result       = await api.GetSaamplesListAsync();
                    if (result != null && result.Count > 0)
                    {
                        using (var db = new KaamelottDB())
                        {
                            foreach (var apisample in result)
                            {
                                if (db.Saamples.Where(x => x.Title == apisample.Title).FirstOrDefault() == null)
                                {
                                    db.Saamples.Add(apisample);
                                }
                                else
                                {
                                    db.Saamples.Update(apisample);
                                }
                            }
                            await db.SaveChangesAsync();
                        }
                    }
                }

                //Dans tous les cas désormais on récupère les infos de la DB
                using (var db = new KaamelottDB())
                {
                    AllSamples = db.Saamples.ToList();
                    ListePerso = AllSamples.Select(x => x.Character).Distinct().OrderBy(x => x).ToList();
                    FilterSamples();
                }
            });
            IsBusy = false;
        }