public List <ArmyModelDAL> ArmyModelsFindByFactionID(int ArmyID, int FactionID, int Skip, int Take) { //this will bring back all the models of a certain faction, with quantities if possible //Outer join used to show all models possible in the army that is being edited in MVC //skip / take is for future implementation of paging @ToDo List <ArmyModelDAL> ReturnValue = new List <ArmyModelDAL>(); CheckConnection(); using (SqlCommand command = new SqlCommand("ArmyModelsFindByFactionID", _con)) { //try is to catch any problems that could happen when using the SQL connection and log them. command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ArmyID", ArmyID); command.Parameters.AddWithValue("@FactionID", FactionID); command.Parameters.AddWithValue("@Skip", Skip); command.Parameters.AddWithValue("@Take", Take); using (SqlDataReader reader = command.ExecuteReader()) { //Using is used to make sure the heavy recources are disposed properly with dispose ArmyModelMapper am = new ArmyModelMapper(reader); while (reader.Read()) { ReturnValue.Add(am.ToArmyModel(reader)); } } } return(ReturnValue); }
public List <ArmyModelDAL> ArmyModelsFindByArmyID(int ArmyID, int Skip, int Take) { //this will bring back all the models of a certain army, with quantities. //for showing an army detail page List <ArmyModelDAL> ReturnValue = new List <ArmyModelDAL>(); CheckConnection(); try { //try is to catch any problems that could happen when using the SQL connection and log them. using (SqlCommand command = new SqlCommand("ArmyModelsFindByArmyID", _con)) { //Using is used to make sure the heavy recources are disposed properly with dispose command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ArmyID", ArmyID); command.Parameters.AddWithValue("@Skip", Skip); command.Parameters.AddWithValue("@Take", Take); using (SqlDataReader reader = command.ExecuteReader()) { ArmyModelMapper am = new ArmyModelMapper(reader); while (reader.Read()) { ReturnValue.Add(am.ToArmyModel(reader)); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }
public ArmyModelDAL ArmyModelsFindByArmyIDAndModelID(int ArmyID, int ModelID) { //this will bring back a certain model of a certain army, with it's quantities. (expect 1) ArmyModelDAL ReturnValue = new ArmyModelDAL(); CheckConnection(); try { //try is to catch any problems that could happen when using the SQL connection and log them. using (SqlCommand command = new SqlCommand("ArmyModelFindByArmyIDAndModelID", _con)) { //Using is used to make sure the heavy recources are disposed properly with dispose command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ArmyID", ArmyID); command.Parameters.AddWithValue("@ModelID", ModelID); using (SqlDataReader reader = command.ExecuteReader()) { ArmyModelMapper amm = new ArmyModelMapper(reader); int count = 0; while (reader.Read()) { ReturnValue = amm.ToArmyModel(reader); count++; } if (count > 1) { throw new Exception($"{count} Multiple Models found for ID {ModelID} & {ArmyID}"); } } } } catch (Exception oops) when(Error.Log(oops)) { //it's all done in the error.log } return(ReturnValue); }