Example #1
0
        public async Task <int> UpsertChecklistCompletion(ChecklistCompletion completion)
        {
            var checklist = await GetChecklist(completion.checklist_id);

            if (completion.id == 0)
            {
                var idResults = await QueryAsync <IdResult>("insert into checklist_completions(checklist_id, notes, created_at, " +
                                                            "updated_at) values (@checklist_id, @notes, current_timestamp, " +
                                                            "current_timestamp) returning id", completion);

                var id = idResults.Single().id;
                await tds.RecordEntry($"Completed Checklist {checklist.name}",
                                      Constants.TimelineReferences.ChecklistCompletion, id);

                return(id);
            }

            await Execute("update checklist_completions set notes=@notes, updated_at=current_timestamp " +
                          "where id=@id", completion);

            return(completion.id);
        }
Example #2
0
        public async Task <CompletedChecklist> SaveCompletedChecklist(int checklist_id, string notes, List <ChecklistCompletionItem> items)
        {
            var checklistCompletion = new ChecklistCompletion {
                checklist_id = checklist_id, notes = notes
            };

            var id = await this.UpsertChecklistCompletion(checklistCompletion);

            foreach (var completionItem in items)
            {
                completionItem.checklist_completion_id = id;
                await this.UpsertChecklistCompletionItem(completionItem);
            }

            var checklistInfo = await GetChecklistCompletion(id);

            var completedItems = await GetCompletedChecklistItemInfo(id);

            return(new CompletedChecklist {
                Checklist = checklistInfo, Items = completedItems, id = id
            });
        }