public List <RoleDAL> GetRoles(int skip, int take) { List <RoleDAL> proposedReturnValue = new List <RoleDAL>(); 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()) { RoleDAL r = m.RoleFromReader(reader); proposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(proposedReturnValue); }
public RoleDAL Role_FindByRoleID(int roleID) { RoleDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("Role_FindByRoleID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@RoleID", roleID); using (SqlDataReader reader = command.ExecuteReader()) { RoleMapper mapper = new RoleMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = mapper.RoleFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Role with key {roleID}"); } } } } catch (Exception ex) when(Log(ex)) { // No access to scope - Exception thrown before entering } return(ProposedReturnValue); }
// ----- Read ----- // public List <RoleDAL> Roles_Get(int skip, int take) { List <RoleDAL> proposedReturnValue = new List <RoleDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("Roles_Get", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { RoleMapper mapper = new RoleMapper(reader); while (reader.Read()) { RoleDAL reading = mapper.RoleFromReader(reader); proposedReturnValue.Add(reading); } } } } catch (Exception ex) when(Log(ex)) { // No access to scope - Exception thrown before entering } return(proposedReturnValue); }
//ROLE public RoleDal FindRoleByID(int RoleID) { RoleDal 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); }