public ResponseProviderList GetAllProviders() { ResponseProviderList theResponse = new ResponseProviderList(); openDataConnection(); SqlCommand getAll = new SqlCommand("GetAllProviders", theConnection); getAll.CommandType = System.Data.CommandType.StoredProcedure; theReader = getAll.ExecuteReader(); if (theReader.HasRows) { theResponse.providers = new List<Provider>(); while (theReader.Read()) { Provider thisProvider = new Provider(); thisProvider.providerID = (int)theReader["ProviderID"]; thisProvider.providerName = theReader["ProviderName"].ToString(); theResponse.providers.Add(thisProvider); } 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 CreateProvider(Provider aProviderModel) { Response theResponse = new Response(); if (aProviderModel == null) { theResponse.statusCode = 2; theResponse.statusDescription = "Provider Model missing"; } else { if (aProviderModel.providerName == null || aProviderModel.providerName.Equals("")) { theResponse.statusDescription = "Provider Name is missing"; } if (theResponse.statusDescription.Equals("")) { bool doesProviderExist = providerExists(aProviderModel.providerName); if (doesProviderExist) { theResponse.statusCode = 3; theResponse.statusDescription = "The provider " + aProviderModel.providerName + " already exists"; return theResponse; } openDataConnection(); SqlCommand addProvider = new SqlCommand("CreateProvider", theConnection); addProvider.Parameters.AddWithValue("@providerName", aProviderModel.providerName); addProvider.CommandType = System.Data.CommandType.StoredProcedure; int numRowsAffected = 0; try { numRowsAffected = addProvider.ExecuteNonQuery(); } catch (Exception _exception) { theResponse.statusCode = 6; theResponse.statusDescription = _exception.Message; } if (numRowsAffected > 0) { theResponse.statusCode = 0; theResponse.statusDescription = ""; } else { theResponse.statusCode = 6; theResponse.statusDescription = "The provider " + aProviderModel.providerName + " could not be created"; } closeDataConnection(); } else { theResponse.statusCode = 2; theResponse.statusDescription = "Provider model missing"; } } return theResponse; }