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); }
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 DroneFromReader(System.Data.SqlClient.SqlDataReader reader) { DronesDAL proposedReturnValue = new DronesDAL(); proposedReturnValue.DroneID = GetInt32OrDefault(reader, OffsetToDroneID); proposedReturnValue.RoleID = GetInt32OrDefault(reader, OffsetToRoleID); proposedReturnValue.DroneName = GetStringOrDefault(reader, OffsetToDroneName); proposedReturnValue.UserID = GetInt32OrDefault(reader, OffsetToUserID); proposedReturnValue.UserName = GetStringOrDefault(reader, OffsetToUserName); proposedReturnValue.Email = GetStringOrDefault(reader, OffsetToEmail); return(proposedReturnValue); }