diff --git a/Components/Pages/Home.razor b/Components/Pages/Home.razor index 50c38a9..0088d2b 100644 --- a/Components/Pages/Home.razor +++ b/Components/Pages/Home.razor @@ -5,16 +5,17 @@ Notebook

Notebook

- +// 2-way data binding between form and local data object +// action biding of form change (submit in this case) -
+
- + // data-binding at form field level
- + // data-binding at form field level
@@ -36,7 +37,7 @@
-

@note.Title

+

@note.Title

// bind data from DB

@note.Content

@@ -45,7 +46,7 @@ - + // conditionally open dialog with local bool parameter
@@ -65,13 +66,13 @@ @code { private string? connectionString; - private List notes = []; + private List notes = []; // for data from DB [SupplyParameterFromForm] - private Note NewNote { get; set; } = new(); + private Note NewNote { get; set; } = new(); // for data interaction with new note form [SupplyParameterFromForm] - private Note EditNote { get; set; } = new(); + private Note EditNote { get; set; } = new(); // for data interaction with edit note form private bool showDialog = false; @@ -86,8 +87,8 @@ using (var conn = new MySqlConnection(connectionString)) { var sql = "SELECT * FROM Note"; - var rows = await conn.QueryAsync(sql); - return rows.ToList(); + var rows = await conn.QueryAsync(sql); // iEnum returned + return rows.ToList(); // convert to list } } @@ -98,11 +99,11 @@ try { var sql = "SELECT * FROM Note WHERE Id = @Id"; - return await conn.QuerySingleAsync(sql, new { Id = id }); + return await conn.QuerySingleAsync(sql, new { Id = id }); //.QuerySingleAsyn can throw error must use try...catch...block } catch (InvalidOperationException) { - throw; + throw; // disregard error and continue } } } @@ -118,7 +119,7 @@ }); } NewNote = new(); - notes = await GetNotesAsync(); + notes = await GetNotesAsync(); // refresh/reload the display with updated contents (one new note added) } private async Task DisplayDialog(int id) @@ -138,7 +139,7 @@ using (var conn = new MySqlConnection(connectionString)) { var sql = "UPDATE Note SET Title = @Title, Content = @Content WHERE Id = @Id"; - await conn.ExecuteAsync(sql, EditNote); + await conn.ExecuteAsync(sql, EditNote); // the object EditNote already exits, no need to initiate with new kywd } CloseDialog(); notes = await GetNotesAsync(); @@ -154,4 +155,4 @@ notes = await GetNotesAsync(); } -} \ No newline at end of file +}