/// <summary> /// Retrieves a single Note Record from the database /// </summary> /// <param name="id">Note identifier</param> public async Task <Note> GetNote(int id) { Note noteRecord = null; using (var conn = GetConnection()) { conn.Open(); var cmd = new MySqlCommand("SELECT * FROM note WHERE NoteId = @noteId", conn); cmd.Parameters.AddWithValue("@noteId", id); using (var reader = await cmd.ExecuteReaderAsync()) { while (reader.Read()) { noteRecord = new Note() { NoteId = Convert.ToUInt32(reader["NoteId"]), CategoryId = Convert.ToUInt32(reader["CategoryId"]), NoteClassification = (NoteClassification)Convert.ToUInt32(reader["NoteClassification"]), NoteTitle = reader["NoteTitle"].ToString(), APP_GUID = reader["APP_GUID"].ToString(), NoteContent = reader["NoteContent"].ToString(), NoteCoordinates = await BasicCoordinatesDBContext.GetGeoposition(Convert.ToUInt32(reader["NoteId"]), Common.CoordinatesParentType.Note), NoteDatetime = ConversionHelpers.SafeGetDateTime(reader, reader.GetOrdinal("NoteDatetime")), CreatedAt = Convert.ToDateTime(reader["CreatedAt"]), CreatedBy = Convert.ToUInt32(reader["CreatedBy"]), ModifiedAt = ConversionHelpers.SafeGetDateTime(reader, reader.GetOrdinal("ModifiedAt")), ModifiedBy = ConversionHelpers.SafeGetInt(reader, reader.GetOrdinal("ModifiedBy")), }; } } } return(noteRecord); }
/// <summary> /// Retrieves the whole list of Note Records from the database /// </summary> public async Task <List <Note> > GetNotes() { var list = new List <Note>(); using (var conn = GetConnection()) { conn.Open(); var cmd = new MySqlCommand("SELECT * FROM note", conn); using (var reader = await cmd.ExecuteReaderAsync()) { while (reader.Read()) { var coordinates = new BasicGeoposition(Convert.ToUInt32(reader["NoteId"]), BasicGeoposition.CoordinatesParentType.Note, ConversionHelpers.SafeGetDouble(reader, reader.GetOrdinal("NoteCoordinateLat")), ConversionHelpers.SafeGetDouble(reader, reader.GetOrdinal("NoteCoordinateLng")), ConversionHelpers.SafeGetDouble(reader, reader.GetOrdinal("NoteCoordinateAlt"))); list.Add(new Note() { NoteId = Convert.ToUInt32(reader["NoteId"]), CategoryId = Convert.ToUInt32(reader["CategoryId"]), NoteClassification = (NoteClassification)Convert.ToUInt32(reader["NoteClassification"]), NoteTitle = reader["NoteTitle"].ToString(), APP_GUID = reader["APP_GUID"].ToString(), NoteContent = reader["NoteContent"].ToString(), NoteCoordinates = coordinates, NoteDatetime = ConversionHelpers.SafeGetDateTime(reader, reader.GetOrdinal("NoteDatetime")), CreatedAt = Convert.ToDateTime(reader["CreatedAt"]), CreatedBy = Convert.ToUInt32(reader["CreatedBy"]), ModifiedAt = ConversionHelpers.SafeGetDateTime(reader, reader.GetOrdinal("ModifiedAt")), ModifiedBy = ConversionHelpers.SafeGetInt(reader, reader.GetOrdinal("ModifiedBy")), }); } } } return(list); }