@@ -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
+}