public async Task <JournalEntry> CreateJournalEntry(JournalEntry entry) { var id = await InsertAndReturnId(InsertSql, entry); await tds.RecordEntry("Journaled", Constants.TimelineReferences.Journal, id); return((await QueryAsync <JournalEntry>(SingleSql, new { id })).Single()); }
public async Task <ChecklistItem> UpsertChecklistItem(ChecklistItem item) { var insertSql = "insert into checklist_items(checklist_id, name, type, description, created_at, " + "updated_at) values (@checklist_id, @name, @type, @description, current_timestamp, " + "current_timestamp) returning id"; var updateSql = "update checklist_items set name=@name, type=@type, description=@description, " + "updated_at=current_timestamp where id=@id"; var selectSql = "select * from checklist_items where id=@id"; var updated = await Upsert(insertSql, updateSql, selectSql, item); var checklist = await GetChecklist(item.checklist_id); await tds.RecordEntry($"Edited Checklist {checklist.name}", Constants.TimelineReferences.Checklist, item.checklist_id); return(updated); }
public async Task<Bookmark> Upsert(Bookmark bookmark) { if(bookmark.created_at == default(DateTime)) bookmark.created_at = DateTime.UtcNow; if(bookmark.modified_at == default(DateTime)) bookmark.modified_at = DateTime.UtcNow; var id = bookmark.id; if (bookmark.id == default(int)) { var idResult = await QueryAsync<IdResult>(InsertSql, bookmark); id = idResult.Single().id; await tds.RecordEntry($"Bookmarked {bookmark.title}", Constants.TimelineReferences.Bookmark, id); } else { bookmark.modified_at = DateTime.Now; await Execute(UpdateSql, bookmark); await tds.RecordEntry($"Edited Bookmark {bookmark.title}", Constants.TimelineReferences.Bookmark, id); } return (await QueryAsync<Bookmark>(GetSingleSql, new {id})).Single(); }
public async Task <UserSetting> UpdateSetting(UserSetting setting) { var current = await QueryAsync <UserSetting>(UserSettingSql, setting); if (current.Count == 0) { await Execute(InsertSettingsSql, setting); } else { await Execute(UpdateSettingSql, new { setting.name, newValue = setting.value }); } await tds.RecordEntry($"Edited setting {setting.name}"); current = await QueryAsync <UserSetting>(UserSettingSql, setting); return(current.Single()); }
public async Task AddFeed(string name, string url) { var id = await InsertAndReturnId(AddFeedSql, new { name, url }); await tds.RecordEntry($"Added feed {name}", Constants.TimelineReferences.Feed, id); }