public static ResponseDTO GetAllLegislationByID(int id) { ErrorDTO ErrorResponse = new ErrorDTO(); ResponseDTO Response = new ResponseDTO(); List <LegislationDTO> ListLegislationData = new List <LegislationDTO>(); SqlConnection con = connection.loadDB(); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "SearchLegislationDataByID"; SqlParameter param1 = new SqlParameter(); param1.ParameterName = "ID"; param1.SqlDbType = SqlDbType.NVarChar; param1.Value = id; cmd.Parameters.Add(param1); try { SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { LegislationDTO LegislationData = new LegislationDTO(); LegislationData.ID = reader["ID"].ToString(); LegislationData.Title = reader["title"].ToString(); LegislationData.Description = reader["description"].ToString(); LegislationData.Summary = reader["summary"].ToString(); LegislationData.StartDate = reader["start_date"].ToString(); LegislationData.EndDate = reader["end_date"].ToString(); LegislationData.CategoryCode = reader["category_code"].ToString(); LegislationData.Reporter = reader["reporter"].ToString(); LegislationData.ImplementingAuthority = reader["implementing_authority"].ToString(); LegislationData.IsImportingCountry = reader["is_importing_country"].ToString(); LegislationData.Agency = reader["agency"].ToString(); ListLegislationData.Add(LegislationData); } } Response.Data = ListLegislationData; } catch (Exception ex) { ErrorResponse.Code = 400; ErrorResponse.Message = ex.ToString(); Response.Error = ErrorResponse; } finally { con.Close(); } return(Response); }
public static ResponseDTO GetLegislation(string category_code, string reporter, int page, int size) { ErrorDTO ErrorResponse = new ErrorDTO(); ResponseDTO Response = new ResponseDTO(); List <LegislationDTO> ListLegislationData = new List <LegislationDTO>(); SqlConnection con = connection.loadDB(); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "GetLegislation"; SqlParameter param1 = new SqlParameter(); param1.ParameterName = "CategoryCode"; param1.SqlDbType = SqlDbType.NVarChar; param1.Value = category_code; cmd.Parameters.Add(param1); SqlParameter param2 = new SqlParameter(); param2.ParameterName = "Reporter"; param2.SqlDbType = SqlDbType.NVarChar; param2.Value = reporter; cmd.Parameters.Add(param2); SqlParameter param6 = new SqlParameter(); param6.ParameterName = "Page"; param6.SqlDbType = SqlDbType.Int; param6.Value = page; cmd.Parameters.Add(param6); SqlParameter param5 = new SqlParameter(); param5.ParameterName = "Size"; param5.SqlDbType = SqlDbType.Int; param5.Value = size; cmd.Parameters.Add(param5); try { SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { LegislationDTO LegislationData = new LegislationDTO(); LegislationData.ID = reader["ID"].ToString(); LegislationData.Title = reader["title"].ToString(); LegislationData.Description = reader["description"].ToString(); LegislationData.Summary = reader["summary"].ToString(); LegislationData.StartDate = reader["start_date"].ToString(); LegislationData.EndDate = reader["end_date"].ToString(); LegislationData.CategoryCode = reader["category_code"].ToString(); LegislationData.Reporter = reader["reporter"].ToString(); LegislationData.ImplementingAuthority = reader["implementing_authority"].ToString(); LegislationData.IsImportingCountry = reader["is_importing_country"].ToString(); LegislationData.Agency = reader["agency"].ToString(); ListLegislationData.Add(LegislationData); ErrorResponse.Code = Convert.ToInt64(reader["Total"].ToString()); ErrorResponse.Message = reader["Total_U"].ToString(); } } if (ListLegislationData.Count != 0) { Response.Data = ListLegislationData; } else { Response.Data = null; } Response.Error = ErrorResponse; } catch (Exception ex) { ErrorResponse.Code = 400; ErrorResponse.Message = ex.ToString(); Response.Error = ErrorResponse; } finally { con.Close(); } return(Response); }