private static List <CityItem> CitiesRepository() { List <CityItem> all = new List <CityItem>(); String sql = "dbo.p_City_Get"; SqlConnection cnn = new SqlConnection(ConnectionStrings.sqlUsers); SqlCommand cmd = new SqlCommand(sql, cnn); SqlDataReader rdr = null; cmd.CommandType = CommandType.StoredProcedure; try { cnn.Open(); rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { CityItem x = new CityItem(); x.Value = rdr.GetByte(0).ToString(); x.Text = rdr.GetString(1); x.CultureId = rdr.GetByte(2); x.CountryId = rdr.GetByte(3); all.Add(x); } } } catch (SqlException e) { } catch (Exception ex) { } finally { if (!(rdr == null)) { rdr.Close(); rdr.Dispose(); } cnn.Close(); cnn.Dispose(); cmd.Dispose(); } return(all); }
public static List <CityItem> Cities(int cultureId, int countryId, bool addDefault) { List <CityItem> r = new List <CityItem>(); var x = from a in Properties.Cities where a.CultureId == cultureId && a.CountryId == countryId select a; r = x.ToList <CityItem>(); if (addDefault) { CityItem defaultItem = new CityItem(); defaultItem.Text = Resources.Labels.Labels.Select; defaultItem.Value = "0"; r.Insert(0, defaultItem); } return(r); }