public async Task <long> AddNote(Note note) { using (var conn = new SQLiteConnection(_connectionString)) { conn.Open(); var group = await GetGroupWithConnection(conn, note.Group); long groupID = 0; if (group == null) { groupID = await AddGroupWithConnection(conn, note.Group); } else { groupID = group.ID; } using (var cmd = new SQLiteCommand(SQLQueries.AddNote(), conn)) { cmd.Parameters.Add(new SQLiteParameter("@CloudKey", note.CloudKey)); cmd.Parameters.Add(new SQLiteParameter("@LastMOdified", note.LastModified.ToString())); cmd.Parameters.Add(new SQLiteParameter("@Content", note.Content)); cmd.Parameters.Add(new SQLiteParameter("@GroupID", groupID)); await cmd.ExecuteNonQueryAsync(); } using (var cmdGetID = new SQLiteCommand(SQLQueries.GetLastInsertedRowID(), conn)) return((long)cmdGetID.ExecuteScalar()); } }
private async Task <long> AddGroupWithConnection(SQLiteConnection conn, string groupName) { using (var cmd = new SQLiteCommand(SQLQueries.AddGroup(), conn)) { cmd.Parameters.Add(new SQLiteParameter("@Group", groupName.ToUpper())); await cmd.ExecuteNonQueryAsync(); } using (var cmdGetID = new SQLiteCommand(SQLQueries.GetLastInsertedRowID(), conn)) return((long)await cmdGetID.ExecuteScalarAsync()); }