private List<CityData> AgeByGender(List<CensusCityAge> cityAges) { List<CityData> cityDatas = new List<CityData>(); foreach (CensusCityAge cityAge in cityAges) { CityData cityData = new CityData(); var label = ""; bool haveMin = false; if (cityAge.MinAge == 0) { label = "Under "; } else { label = cityAge.MinAge.ToString() + " "; haveMin = true; } if (cityAge.MaxAge != null) { if (haveMin) { label = label + "- " + cityAge.MaxAge.ToString() + " Years"; } else { label = label + cityAge.MaxAge.ToString() + " Years"; } } else { label = label + "and Older"; } cityData.Text = label; if (cityAge.Population != null) { cityData.Value = cityAge.Population.ToString(); } else { cityData.Value = "n/a"; } cityDatas.Add(cityData); } return cityDatas; }
// // get // AJAX: /City/UICityDataJSON?uiCityDataTypeID=1 public ActionResult UICityDataJSON(int uiCityDataTypeID, int cityID, int stateID) { switch (uiCityDataTypeID) { case 8: //population //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; CensusCityPop cityPop = publicDB.CensusCityPops.Where(p => p.CityID == cityID && p.Year == year).Single(); CityData cityData = new CityData(); cityData.Text = "Total Population"; if (cityPop.Population != null) { cityData.Value = cityPop.Population.ToString(); } else { cityData.Value = "n/a"; } List<CityData> cityDatas = new List<CityData>(); cityDatas.Add(cityData); return Json(cityDatas.Select(x => new { value = x.Value, text = x.Text }), JsonRequestBehavior.AllowGet); break; case 9: // ages (male) List<CensusCityAge> cityAges = publicDB.CityAges.Where(p => p.CityID == cityID && p.Gender == false).ToList(); List<CityData> cityDatas2 = AgeByGender(cityAges); return Json(cityDatas2.Select(x => new { value = x.Value, text = x.Text }), JsonRequestBehavior.AllowGet); break; case 10: // ages (female) List<CensusCityAge> cityAges2 = publicDB.CityAges.Where(p => p.CityID == cityID && p.Gender == true).ToList(); List<CityData> cityDatas3 = AgeByGender(cityAges2); return Json(cityDatas3.Select(x => new { value = x.Value, text = x.Text }), JsonRequestBehavior.AllowGet); break; case 16: // households by type break; case 17: // relationships break; default: break; } //List<UICityDataType> uiCityDataTypes = publicDB.UICityDataTypes.Where(u => u.ParentCityDataTypeID == uiCityDataTypeID && u.Active == true).OrderBy(u => u.SortOrder).ToList(); //return Json(uiCityDataTypes.Select(x => new { value = x.CityDataTypeID, text = x.DisplayText }), JsonRequestBehavior.AllowGet); return null; }