public ResponseProviderWithCDCList GetCDCsForProvider(string providerID) { ResponseProviderWithCDCList theResponse = new ResponseProviderWithCDCList(); string providerName = getProviderNameFromID(Int32.Parse(providerID)); if (providerName == null) { theResponse.statusCode = 2; theResponse.statusDescription = "There is no provider with ID " + providerID; return theResponse; } openDataConnection(); SqlCommand getCDCs = new SqlCommand("GetCDCsForProvider", theConnection); getCDCs.Parameters.AddWithValue("@providerID", providerID); getCDCs.CommandType = System.Data.CommandType.StoredProcedure; theReader = getCDCs.ExecuteReader(); if (theReader.HasRows) { theResponse.providers = new List<ProviderWithCDC>(); ProviderWithCDC thisProvider = new ProviderWithCDC(); thisProvider.providerName = providerName; thisProvider.providerID = Int32.Parse(providerID); thisProvider.cdcs = new List<CDC>(); theResponse.providers.Add(thisProvider); while (theReader.Read()) { CDC thisCDC = new CDC(); thisCDC.id = (int)theReader["CDCID"]; thisCDC.name = theReader["CDCName"].ToString(); thisCDC.address = theReader["CDCAddress"].ToString(); thisCDC.state = theReader["CDCState"].ToString(); thisCDC.zip = theReader["CDCZip"].ToString(); thisCDC.phone = theReader["CDCPhone"].ToString(); thisCDC.email = theReader["CDCEmailAddress"].ToString(); thisCDC.providerID = thisProvider.providerID; thisProvider.cdcs.Add(thisCDC); } theResponse.statusCode = 0; theResponse.statusDescription = ""; } else { theResponse.statusCode = 2; theResponse.statusDescription = "There are no Providers in the database"; } theReader.Close(); closeDataConnection(); return theResponse; }
public ResponseProviderWithCDCList GetAllProvidersWithCDCs() { ResponseProviderWithCDCList theResponse = new ResponseProviderWithCDCList(); openDataConnection(); SqlCommand getAll = new SqlCommand("GetAllProvidersWithCDCs", theConnection); getAll.CommandType = System.Data.CommandType.StoredProcedure; theReader = getAll.ExecuteReader(); if (theReader.HasRows) { int currentProviderID = 0; ProviderWithCDC thisProvider = null; theResponse.providers = new List<ProviderWithCDC>(); while (theReader.Read()) { int thisProviderID = (int)theReader["ProviderID"]; if (currentProviderID != thisProviderID) { thisProvider = new ProviderWithCDC(); thisProvider.providerID = (int)theReader["ProviderID"]; thisProvider.providerName = theReader["ProviderName"].ToString(); theResponse.providers.Add(thisProvider); thisProvider.cdcs = new List<CDC>(); currentProviderID = thisProviderID; } CDC thisCDC = new CDC(); thisCDC.id = (int)theReader["CDCID"]; thisCDC.name = theReader["CDCName"].ToString(); thisCDC.address = theReader["CDCAddress"].ToString(); thisCDC.state = theReader["CDCState"].ToString(); thisCDC.zip = theReader["CDCZip"].ToString(); thisCDC.phone = theReader["CDCPhone"].ToString(); thisCDC.email = theReader["CDCEmailAddress"].ToString(); thisCDC.providerID = thisProvider.providerID; thisProvider.cdcs.Add(thisCDC); } theResponse.statusCode = 0; theResponse.statusDescription = ""; } else { theResponse.statusCode = 2; theResponse.statusDescription = "There are no Providers in the database"; } theReader.Close(); closeDataConnection(); return theResponse; }