public static LocationNameBLDto ToLocationNamesBLDTO(this LocationNameDADto rec) { return(new LocationNameBLDto { location = rec.location }); }
public List <LocationNameDADto> GetListOfLocations(Locations locations, string region) { List <LocationNameDADto> locationNames = new List <LocationNameDADto>(); using (SqlConnection connection = new SqlConnection(_configuration.GetConnectionString("MSSQL_MainDB"))) { connection.Open(); SqlCommand sqlCommand = new SqlCommand(); if (locations == Locations.Global && region == "nation") { sqlCommand.CommandText = "select distinct Country as Country from LocationsGlobal"; } else if (locations == Locations.US && region == "state") { sqlCommand.CommandText = "select distinct state as [State] from Locations_US order by [State]"; } else if (locations == Locations.US && region == "county") { sqlCommand.CommandText = "Select distinct county as County from Locations_US order by County"; } sqlCommand.Connection = connection; SqlDataReader reader = sqlCommand.ExecuteReader(); try { while (reader.Read()) { LocationNameDADto location = new LocationNameDADto(); location.location = (locations == Locations.Global) ? (string)reader["Country"] : (locations == Locations.US && region == "state") ? (string)reader["State"] : (locations == Locations.US && region == "county") ? (string)reader["County"] : "Use lower case letters for your region"; locationNames.Add(location); } } catch (SqlException ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(locationNames); }