public RolesDAL FindRoleByID(int RoleID) { RolesDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindRoleByID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@RoleID", RoleID); using (SqlDataReader reader = command.ExecuteReader()) { RoleMapper m = new RoleMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.RoleFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Role with key {RoleID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public List <RolesDAL> GetRoles(int skip, int take) { List <RolesDAL> ProposedReturnValue = new List <RolesDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetRoles", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { RoleMapper m = new RoleMapper(reader); while (reader.Read()) { RolesDAL r = m.RoleFromReader(reader); ProposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public RolesDAL RoleFromReader(System.Data.SqlClient.SqlDataReader reader) { RolesDAL proposedReturnValue = new RolesDAL(); proposedReturnValue.RoleID = GetInt32OrDefault(reader, OffsetToRoleID); proposedReturnValue.RoleName = GetStringOrDefault(reader, OffsetToRoleName); return(proposedReturnValue); }