Ejemplo n.º 1
0
        public async Task<WeekRoot> GetWeekRootAsync(DateTime weekDate, bool forceUpdate)
        {
            if (await database.IsEmptyAsync<WeekRoot>())
            {
                var weekRoot = await LoadWeekRootFromWebAsync(weekDate);
                await database.SaveItemAsync(weekRoot);
                return weekRoot;
            }
            else
            {
				var weeks = await database.GetItemsAsync<WeekRoot>();

				var weekFromDb = (await database.GetItemsAsync<WeekRoot>()).Where(w => w.Week.DateEqual(weekDate)).SingleOrDefault();
                if (weekFromDb == null)
                {
                    var newWeek = (await LoadWeekRootFromWebAsync(weekDate));
                    await database.SaveItemAsync(newWeek);
                    return newWeek;
                }
				else if (forceUpdate)
				{
					var newWeek = (await LoadWeekRootFromWebAsync(weekDate));
					await database.DeleteItemsAsync<WeekRoot>(w => w.Week.DateEqual(weekDate));
					await database.SaveItemAsync(newWeek);
					return newWeek;
				}
                else
                {
                    return weekFromDb;
                }
            }
        }
 private void InitDatabase()
 {
     CreateTables().Wait();
     database.DeleteItemsAsync <WeekSchedule>((s) => true).Wait();
 }