public ObservationsDAL FindObservation(int ObsID) { ObservationsDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindObservation", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ObsID", ObsID); using (SqlDataReader reader = command.ExecuteReader()) { ObservationsMapper m = new ObservationsMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.ObservationFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Observation with key {ObsID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public List <ObservationsDAL> GetObservationsRelatedToObs(int skip, int take) { List <ObservationsDAL> ProposedReturnValue = new List <ObservationsDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetObservationsRelatedToObs", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { ObservationsMapper m = new ObservationsMapper(reader); while (reader.Read()) { ObservationsDAL r = m.ObservationFromReader(reader); ProposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public ObservationsDAL ObservationFromReader(System.Data.SqlClient.SqlDataReader reader) { ObservationsDAL proposedReturnValue = new ObservationsDAL(); proposedReturnValue.ObsID = GetInt32OrDefault(reader, OffsetToObsID); proposedReturnValue.Speed = GetInt32OrDefault(reader, OffsetToSpeed); proposedReturnValue.LatNumber = GetStringOrDefault(reader, OffsetToLatNumber); proposedReturnValue.LongNumber = GetStringOrDefault(reader, OffsetToLongNumber); proposedReturnValue.PlateID = GetInt32OrDefault(reader, OffsetToPlateID); proposedReturnValue.RegisteredOwner = GetStringOrDefault(reader, OffsetToRegisteredOwner); proposedReturnValue.DroneID = GetInt32OrDefault(reader, OffsetToDroneID); proposedReturnValue.DroneName = GetStringOrDefault(reader, OffsetToDroneName); return(proposedReturnValue); }