Пример #1
0
        //
        // get
        // AJAX: /City/CitiesWithinPercentJSON?percent=3
        public ActionResult CitiesWithinPercentJSON(int excludeCityID, int stateID, int homePop, double percent)
        {
            //get year for this data
            var dataSetYear = publicDB.DataSetCurrentYears.Where(x => x.StateID == stateID && x.EntityType == (byte)EntityType.City && x.DataSet == (byte)DataSet.USCensus && x.DataSetSubtype == (byte)DataSetSubtype.Primary).Single();
            byte year = dataSetYear.Year;

            var cities1 =  from c in publicDB.Cities join p in publicDB.CensusCityPops on c.CityID equals p.CityID into cp
                           from p in cp
                           where p.Year == year &&
                           p.Population >= homePop * (1 - percent/100) &&
                           p.Population <= homePop * (1 + percent/100) &&
                           c.StateID == stateID &&
                           c.CityID != excludeCityID
                           select new {p.CityID, c.CityUniqueName, p.Population, c.StateID};

            List<CityNameList> cities = new List<CityNameList>();
            foreach (var x in cities1)
            {
                CityNameList cityItem = new CityNameList();
                cityItem.CityID = x.CityID;
                string showPop = "";
                if (x.Population == null)
                {
                    showPop = "none";
                }
                else
                {
                    showPop = x.Population.ToString();
                }
                string showText = x.CityUniqueName + " (pop " + showPop + ")";
                cityItem.CityText = showText;
                cityItem.CityPopulation = x.Population;
                cityItem.CityUniqueName = x.CityUniqueName;
                cityItem.CityStateID = x.StateID;
                cities.Add(cityItem);
            }
            return Json(cities.Select(x => new { value = x.CityID, text = x.CityText, name = x.CityUniqueName, population = x.CityPopulation, stateID = x.CityStateID }), JsonRequestBehavior.AllowGet);
        }
Пример #2
0
        //
        // get
        // AJAX: /City/SingleCityPopJSON?city=3900142
        public ActionResult SingleCityPopJSON(int cityID)
        {
            City singleCity = publicDB.Cities.Where(c => c.CityID == cityID).Single();
            int cityValue = singleCity.CityID;

            //get year for this data
            var dataSetYear = publicDB.DataSetCurrentYears.Where(x => x.StateID == singleCity.StateID && x.EntityType == (byte)EntityType.City && x.DataSet == (byte)DataSet.USCensus && x.DataSetSubtype == (byte)DataSetSubtype.Primary).Single();
            byte year = dataSetYear.Year;

            int? cityPop = publicDB.CensusCityPops.Where(p => p.CityID == cityID && p.Year == year).Select(p => p.Population).SingleOrDefault();
            string showPop = "";
            if (cityPop == null)
            {
                showPop = "none";
            }
            else
            {
                showPop = cityPop.ToString();
            }

            string showText = singleCity.CityUniqueName + " (pop " + showPop + ")";

            CityNameList cityItem = new CityNameList();
            cityItem.CityID = cityValue;
            cityItem.CityText = showText;
            cityItem.CityPopulation = cityPop;
            cityItem.CityUniqueName = singleCity.CityUniqueName;
            cityItem.CityStateID = singleCity.StateID;
            List<CityNameList> cities = new List<CityNameList>();
            cities.Add(cityItem);

            return Json(cities.Select(x => new { value = x.CityID, text = x.CityText, name = x.CityUniqueName, population = x.CityPopulation, stateID = x.CityStateID }), JsonRequestBehavior.AllowGet);
        }