public List <DronesDAL> GetDronesRelatedToUser(int UserID, int skip, int take) { List <DronesDAL> ProposedReturnValue = new List <DronesDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetDronesRelatedToUser", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@UserID", UserID); command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { DronesMapper m = new DronesMapper(reader); while (reader.Read()) { DronesDAL r = m.DroneFromReader(reader); ProposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public DronesDAL FindDrone(int DroneID) { DronesDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindDrone", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@DroneID", DroneID); using (SqlDataReader reader = command.ExecuteReader()) { DronesMapper m = new DronesMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.DroneFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Drone with key {DroneID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }