public async Task AddItems(List <BindableItem> items) { using (var db = new TodoistContext()) { await db.Items.AddRangeAsync(items.Select(i => i.ToDbItem())); await db.SaveChangesAsync(); } }
public async Task <User> GetUser() { using (var db = new TodoistContext()) { var user = await db.Users.Select(u => u.ToUser()).FirstOrDefaultAsync(); return(user); } }
public async Task <IEnumerable <BindableItem> > RetrieveItems(Expression <Func <Item, bool> > query) { using (var db = new TodoistContext()) { var dbItems = await db.Items.Where(item => string.IsNullOrWhiteSpace(item.Content) == false).Where(query).ToListAsync(); var items = dbItems.Select(item => item .ToBindableItem()) .OrderBy(item => item.Content.ToLower()); return(items); } }
public async Task SaveUser(User user) { if (user == null) { return; } using (var db = new TodoistContext()) { await db.Database.ExecuteSqlCommandAsync("delete from users"); db.Users.Add(user.ToDbUser()); await db.SaveChangesAsync(); } }