public ArmyDAL ArmyFindByID(int ArmyID) { // retrieve a Army by ID (we dont expect multiple records here) ArmyDAL ReturnValue = null; CheckConnection(); try { using (SqlCommand command = new SqlCommand("ArmyFindByID", _con)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ArmyID", ArmyID); using (SqlDataReader reader = command.ExecuteReader()) { ArmyMapper am = new ArmyMapper(reader); int count = 0; while (reader.Read()) { ReturnValue = am.ToArmy(reader); count++; } if (count > 1) { throw new Exception($"{count} Multiple Army found for ID {ArmyID}"); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }
public List <ArmyDAL> ArmiesFindByUserID(int UserID, int Skip, int Take) { // retrieve armies by userID (we expect multiple records here) List <ArmyDAL> ReturnValue = new List <ArmyDAL>(); CheckConnection(); try { using (SqlCommand command = new SqlCommand("ArmiesFindByUserID", _con)) { 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()) { ArmyMapper am = new ArmyMapper(reader); while (reader.Read()) { ReturnValue.Add(am.ToArmy(reader)); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }
public List <ArmyDAL> ArmiesGetAll(int Skip, int Take) { // retrieves all Armies List <ArmyDAL> ReturnValue = new List <ArmyDAL>(); CheckConnection(); try { using (SqlCommand command = new SqlCommand("ArmiesGetAll", _con)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@skip", Skip); command.Parameters.AddWithValue("@take", Take); using (SqlDataReader reader = command.ExecuteReader()) { ArmyMapper am = new ArmyMapper(reader); while (reader.Read()) { ReturnValue.Add(am.ToArmy(reader)); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }