public FactionDAL FactionFindByID(int FactionID) { // retrieve a Faction by ID (we dont expect multiple records here) FactionDAL ReturnValue = null; CheckConnection(); try { using (SqlCommand command = new SqlCommand("FactionFindByID", _con)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@FactionID", FactionID); using (SqlDataReader reader = command.ExecuteReader()) { // check for multiple records, throw oops if so. We should only get one FactionMapper fm = new FactionMapper(reader); int count = 0; while (reader.Read()) { ReturnValue = fm.ToFaction(reader); count++; } if (count > 1) { throw new Exception($"{count} Multiple Factions found for ID {FactionID}"); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }
public List <FactionDAL> FactionsGetAll(int Skip, int Take) { // retrieves all Factions List <FactionDAL> ReturnValue = new List <FactionDAL>(); CheckConnection(); try { using (SqlCommand command = new SqlCommand("FactionsGetAll", _con)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@skip", Skip); command.Parameters.AddWithValue("@take", Take); using (SqlDataReader reader = command.ExecuteReader()) { FactionMapper fm = new FactionMapper(reader); while (reader.Read()) { FactionDAL item = fm.ToFaction(reader); ReturnValue.Add(item); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }