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 CDC GetCDCForStop(int stopID)
        {
            CDC thisCDC = null;

            openDataConnection();

            SqlCommand getCDC = new SqlCommand("GetCDCForStop", theConnection);
            getCDC.Parameters.AddWithValue("@stopID", stopID);
            getCDC.CommandType = System.Data.CommandType.StoredProcedure;

            try
            {
                theReader = getCDC.ExecuteReader();

                if (theReader.HasRows)
                {
                    while (theReader.Read())
                    {
                        thisCDC = new CDC();

                        thisCDC.name = theReader["CDCName"].ToString();

                    }
                }
            }
            catch (Exception _exception)
            {

            }

            closeDataConnection();

            return thisCDC;
        }
        public ResponseCDCList GetAllCDCsForProvider(string providerID)
        {
            ResponseCDCList theResponse = new ResponseCDCList();

            openDataConnection();

            SqlCommand cmdRead = new SqlCommand("GetAllCDCs", theConnection);
            cmdRead.CommandType = System.Data.CommandType.StoredProcedure;

            theReader = cmdRead.ExecuteReader();

            if (theReader.HasRows)
            {
                List<CDC> allCDCs = new List<CDC>();

                int wantedProviderID = Int32.Parse(providerID);

                while (theReader.Read())
                {
                    int thisProviderID = (int)theReader["ProviderID"];

                    if (thisProviderID > 0 && thisProviderID == wantedProviderID)
                    {
                        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 = (int)theReader["ProviderID"];

                        allCDCs.Add(thisCDC);
                    }
                }

                theResponse.cdcs = allCDCs;

                theResponse.statusCode = 0;
                theResponse.statusDescription = "";
            }
            else
            {
                theResponse.statusCode = 4;
                theResponse.statusDescription = "No CDCs have been defined";
            }

            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;
        }
        public Response CreateCDC(CDC aCDCModel)
        {
            Response theResponse = new Response();

            if (aCDCModel != null)
            {
                if (aCDCModel.name == null || aCDCModel.name.Equals(""))
                {
                    theResponse.statusDescription = "CDC Name was not provided";
                }
                if (aCDCModel.providerID == 0)
                {
                    theResponse.statusDescription = "CDC Provider ID was not provided";
                }

                if (theResponse.statusDescription.Equals(""))
                {
                    if (cdcExists(aCDCModel.name))
                    {
                        theResponse.statusCode = 3;
                        theResponse.statusDescription = "A CDC by the name of " + aCDCModel.name + " already exists";

                        return theResponse;
                    }

                    openDataConnection();

                    SqlCommand cmdCreate = null;

                    if (aCDCModel.address == null && aCDCModel.state == null && aCDCModel.zip == null && aCDCModel.phone == null && aCDCModel.email == null)
                    {
                        cmdCreate = new SqlCommand("CreateCDC", theConnection);
                    }
                    else
                    {
                        cmdCreate = new SqlCommand("CreateCDCWithDetail", theConnection);
                        cmdCreate.Parameters.AddWithValue("@cdcAddress", aCDCModel.address);
                        cmdCreate.Parameters.AddWithValue("@cdcState", aCDCModel.state);
                        cmdCreate.Parameters.AddWithValue("@cdcZip", aCDCModel.zip);
                        cmdCreate.Parameters.AddWithValue("@cdcPhone", aCDCModel.phone);
                        cmdCreate.Parameters.AddWithValue("@cdcEmailAddress", aCDCModel.email);
                    }
                    cmdCreate.Parameters.AddWithValue("@cdcName", aCDCModel.name);
                    cmdCreate.Parameters.AddWithValue("@providerID", aCDCModel.providerID);
                    cmdCreate.CommandType = System.Data.CommandType.StoredProcedure;

                    try
                    {
                        int numRowsAffected = cmdCreate.ExecuteNonQuery();

                        if (numRowsAffected > 0)
                        {
                            theResponse.statusCode = 0;
                            theResponse.statusDescription = "";
                        }
                        else
                        {
                            theResponse.statusCode = 6;
                            theResponse.statusDescription = "Specified CDC could not be added";
                        }
                    }
                    catch (Exception _exception)
                    {
                        theResponse.statusCode = 6;
                        theResponse.statusDescription = _exception.Message;
                    }

                    closeDataConnection();
                }
                else
                {
                    theResponse.statusCode = 6;
                }
            }
            else
            {
                theResponse.statusCode = 6;
                theResponse.statusDescription = "Expected CDC Model not recieved";
            }

            return theResponse;
        }