Пример #1
0
        public async Task <IQueryable <T> > GetList(Func <Task <List <T> > > download)
        {
            bool needToUpdate = false;

            Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var values = localSettings.Values[typeof(T).Name + "SyncDate"];

            if (values != null)
            {
                DateTime dateSync = DateTime.Parse((string)values);
                if (dateSync < DateTime.Now.AddDays(-7))
                {
                    needToUpdate = true;
                }
            }
            else
            {
                needToUpdate = true;
            }
            IQueryable <T> query;

            if (!needToUpdate)
            {
                // Get from database
                using (var bddContext = new BddContext())
                {
                    query = bddContext.Set <T>().ToList().AsQueryable();
                }
            }
            else
            {
                // Update database
                query = (await download()).AsQueryable();
            }
            return(query);
        }