public List <HistoryDAL> GetHistoryByPlateID(int PlateID, int skip, int take) { List <HistoryDAL> ProposedReturnValue = new List <HistoryDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetHistoryByPlateID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@PlateID", PlateID); command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { HistoryMapper m = new HistoryMapper(reader); while (reader.Read()) { HistoryDAL r = m.HistoryFromReader(reader); ProposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public HistoryDAL FindHistoryByID(int HistoryID) { HistoryDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindHistoryByID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@HistoryID", HistoryID); using (SqlDataReader reader = command.ExecuteReader()) { HistoryMapper m = new HistoryMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.HistoryFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 History with key {HistoryID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }