public async Task <ActionResult <List <Models.ReasonForEntry> > > GetReasonForEntryList() { System.Text.StringBuilder sqlStatement; DateTime processingDateTime; NpgsqlConnection sqlConnection; NpgsqlCommand sqlCommandGetResultOfCandidacyList; NpgsqlDataReader sqlDataReaderGetResultOfCandidacyList; try { List <Models.ReasonForEntry> returnValue = new List <Models.ReasonForEntry>(); processingDateTime = System.DateTime.Now; using (sqlConnection = new NpgsqlConnection(configuration["ConnectionStrings:PolitiScout"])) { await sqlConnection.OpenAsync(); sqlStatement = new System.Text.StringBuilder(); sqlStatement.Append("SELECT r.reason_for_entry_id, r.description "); sqlStatement.Append(" FROM reason_for_entry r "); sqlStatement.Append(" ORDER BY r.description "); sqlCommandGetResultOfCandidacyList = sqlConnection.CreateCommand(); sqlCommandGetResultOfCandidacyList.CommandText = sqlStatement.ToString(); sqlCommandGetResultOfCandidacyList.CommandTimeout = 600; await sqlCommandGetResultOfCandidacyList.PrepareAsync(); using (sqlDataReaderGetResultOfCandidacyList = await sqlCommandGetResultOfCandidacyList.ExecuteReaderAsync(System.Data.CommandBehavior.CloseConnection)) { while (await sqlDataReaderGetResultOfCandidacyList.ReadAsync()) { Models.ReasonForEntry reasonForEntry = new Models.ReasonForEntry(); reasonForEntry.reasonForEntryId = sqlDataReaderGetResultOfCandidacyList.GetInt32(ApplicationValues.REASON_FOR_ENTRY_LIST_QUERY_RESULT_COLUMN_OFFSET_REASON_FOR_ENTRY_ID); reasonForEntry.description = sqlDataReaderGetResultOfCandidacyList.GetString(ApplicationValues.REASON_FOR_ENTRY_LIST_QUERY_RESULT_COLUMN_OFFSET_DESCRIPTION); returnValue.Add(reasonForEntry); } ; await sqlDataReaderGetResultOfCandidacyList.CloseAsync(); }; await sqlConnection.CloseAsync(); } // using (sqlConnection = new NpgsqlConnection(configuration["ConnectionStrings:PolitiScout"])) return(Ok(returnValue)); } catch (Exception ex1) { logger.LogError(string.Format("Unhandled exception occurred in DictionaryWSController::GetReasonForEntryList(). Message is {0}", ex1.Message)); if (ex1.InnerException != null) { logger.LogError(string.Format(" -- Inner exception message is {0}", ex1.InnerException.Message)); if (ex1.InnerException.InnerException != null) { logger.LogError(string.Format(" -- -- Inner exception message is {0}", ex1.InnerException.InnerException.Message)); } } logger.LogError(string.Format("{0}", ex1.StackTrace)); return(StatusCode(StatusCodes.Status500InternalServerError, ex1.Message)); } } // GetReasonForEntryList()
public async Task <ActionResult <Models.ReasonForEntry> > GetReasonForEntry(int reasonForEntryId) { System.Text.StringBuilder sqlStatement; DateTime processingDateTime; NpgsqlConnection sqlConnection; NpgsqlCommand sqlCommandGetReasonForEntry; NpgsqlDataReader sqlDataReaderGetReasonForEntry; try { Models.ReasonForEntry returnValue = new Models.ReasonForEntry(); processingDateTime = System.DateTime.Now; using (sqlConnection = new NpgsqlConnection(configuration["ConnectionStrings:PolitiScout"])) { await sqlConnection.OpenAsync(); sqlStatement = new System.Text.StringBuilder(); sqlStatement.Append("SELECT r.description "); sqlStatement.Append(" FROM reason_for_entry r "); sqlStatement.Append(" WHERE r.reason_for_entry_id = @reason_for_entry_id "); sqlCommandGetReasonForEntry = sqlConnection.CreateCommand(); sqlCommandGetReasonForEntry.CommandText = sqlStatement.ToString(); sqlCommandGetReasonForEntry.CommandTimeout = 600; sqlCommandGetReasonForEntry.Parameters.Add(new NpgsqlParameter("@reason_for_entry_id", NpgsqlTypes.NpgsqlDbType.Integer)); sqlCommandGetReasonForEntry.Parameters["@reason_for_entry_id"].Value = 0; await sqlCommandGetReasonForEntry.PrepareAsync(); sqlCommandGetReasonForEntry.Parameters["@reason_for_entry_id"].Value = reasonForEntryId; using (sqlDataReaderGetReasonForEntry = await sqlCommandGetReasonForEntry.ExecuteReaderAsync(System.Data.CommandBehavior.CloseConnection)) { if (await sqlDataReaderGetReasonForEntry.ReadAsync()) { returnValue.reasonForEntryId = reasonForEntryId; returnValue.description = sqlDataReaderGetReasonForEntry.GetString(ApplicationValues.REASON_FOR_ENTRY_QUERY_RESULT_COLUMN_OFFSET_DESCRIPTION); } ; await sqlDataReaderGetReasonForEntry.CloseAsync(); }; await sqlConnection.CloseAsync(); } // using (sqlConnection = new NpgsqlConnection(configuration["ConnectionStrings:PolitiScout"])) return(Ok(returnValue)); } catch (Exception ex1) { logger.LogError(string.Format("Unhandled exception occurred in DictionaryWSController::GetReasonForEntry(). Message is {0}", ex1.Message)); if (ex1.InnerException != null) { logger.LogError(string.Format(" -- Inner exception message is {0}", ex1.InnerException.Message)); if (ex1.InnerException.InnerException != null) { logger.LogError(string.Format(" -- -- Inner exception message is {0}", ex1.InnerException.InnerException.Message)); } } logger.LogError(string.Format("{0}", ex1.StackTrace)); return(StatusCode(StatusCodes.Status500InternalServerError, ex1.Message)); } } // GetReasonForEntry()