// get: /city/Details?id=5 public ActionResult Details(int id) { CityDetail cityDetail = new CityDetail(); cityDetail.City = publicDB.Cities.Where(c => c.CityID == id).Single(); cityDetail.UICityDataTypes = publicDB.UICityDataTypes.Where(cdt => cdt.CityDataTypeID > 0 && cdt.DataLevel == 1 && cdt.Active == true).OrderBy(cdt => cdt.SortOrder).ToList(); cityDetail.UICityDataTypeSize = cityDetail.UICityDataTypes.Count() + 2; cityDetail.ComparisonCities = publicDB.Cities.Where(c => c.CityID != id && c.StateID == cityDetail.City.StateID).ToList(); //get year for this data var dataSetYear = publicDB.DataSetCurrentYears.Where(x => x.StateID == cityDetail.City.StateID && x.EntityType == (byte)EntityType.City && x.DataSet == (byte)DataSet.USCensus && x.DataSetSubtype == (byte)DataSetSubtype.Primary).Single(); byte year = dataSetYear.Year; cityDetail.CityPopulation = publicDB.CensusCityPops.Where(p => p.CityID == id && p.Year == year).Select(p => p.Population).Single(); return(View(cityDetail)); }
private void GenerateWeatherReportForToday(CityDetail city) { HttpClient client = new HttpClient { BaseAddress = new Uri("http://api.openweathermap.org") }; string appId = "aa69195559bd4f88d79f9aadeb77a8f6"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Format("/data/2.5/weather?id={0}&APPID={1}", city.id, appId)); HttpResponseMessage httpResponseMessage = client.SendAsync(request).Result; string output = httpResponseMessage.Content.ReadAsStringAsync().Result; var path = String.Format("{0}WeatherReport\\city_{1},{2}_{3}.txt", AppDomain.CurrentDomain.BaseDirectory, city.name, city.country, DateTime.Today.ToString("yyyyMMdd")); System.IO.File.WriteAllText(path, output); }
public List <CityDetail> GetCityByState(string name) { using (var ctx = new ApplicationDbContext()) { var cities = ctx.Cities.Where(e => e.State.Name.Contains(name)).ToList(); foreach (var city in cities) { var foundCity = new CityDetail { ID = city.ID, Name = city.Name, StateID = city.StateID, StateName = city.State.Name }; searchResults.Add(foundCity); } return(searchResults); } }
/// <summary> /// Click event for Add button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { CityDetail findCity = this.CurrentCities.Find(r => r._ID == ((CityDetail)this.lstOptions.SelectedValue)._ID); if (findCity == null) { ((CityDetail)this.lstOptions.SelectedValue).ActionCode = ActionCode.New; ((CityDetail)this.lstOptions.SelectedValue).CreateTimeStamp = System.DateTime.Now; ((CityDetail)this.lstOptions.SelectedValue).EditTimeStamp = System.DateTime.Now; this.CurrentCities.Add((CityDetail)lstOptions.SelectedValue); } else { if (findCity.ActionCode == ActionCode.Delete) { findCity.ActionCode = ActionCode.None; } } this.UpdateLists(); }
public void SaveCityDetails(CityDetailsViewModel cityDetailsViewModel) { try { //string uniqueFileName = null; if (cityDetailsViewModel.Photo != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Files"); //uniqueFileName = Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName; string filePath = Path.Combine(uploadsFolder, Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName); cityDetailsViewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } if (cityDetailsViewModel.StreetsId.Count != 0) { foreach (var streetId in cityDetailsViewModel.StreetsId) { StreetCityDetail streetCityDetail = new StreetCityDetail { CityDetailId = cityDetailsViewModel.CityId, StreetId = streetId }; context.StreetCityDetails.Add(streetCityDetail); } } CityDetail cityDetail = new CityDetail { FullName = cityDetailsViewModel.UserFulName, HomeNumber = cityDetailsViewModel.HomeNumber, FileName = cityDetailsViewModel.Photo.FileName, BirthDate = cityDetailsViewModel.UserBirthDate, CityId = cityDetailsViewModel.CityId }; context.CityDetails.Add(cityDetail); context.SaveChanges(); } catch (Exception ex) { string exception = ex.ToString(); } }
/// <summary> /// Click event for Add All button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddAll_Click(object sender, EventArgs e) { foreach (CityDetail cd in AllCities) { CityDetail findCity = this.CurrentCities.Find(r => r._ID == cd._ID); if (findCity == null) { cd.ActionCode = ActionCode.New; cd.CreateTimeStamp = System.DateTime.Now; cd.EditTimeStamp = System.DateTime.Now; this.CurrentCities.Add(cd); } else { if (cd._ID == findCity._ID) { findCity.ActionCode = findCity.ActionCode == ActionCode.New ? ActionCode.New : ActionCode.None; } } } this.UpdateLists(); }
public JsonResult GetCityDetails(string cityCode) { CityDetail cityLocation = _citiesSoap.GetCityDetail(int.Parse(cityCode)); XElement cityWeatherXElement = _citiesSoap.GetCityWeather(int.Parse(cityCode)); IEnumerable <string> cityWeatherValue = cityWeatherXElement.Elements("temperature") .Select(i => i.Attribute("value").Value); IEnumerable <string> cityWeatherMetric = cityWeatherXElement.Elements("temperature") .Select(i => i.Attribute("unit").Value); char cityWeatherMetricChar = cityWeatherMetric.ElementAt(0) == "metric" ? 'C' : 'F'; string cityTemperature = cityWeatherValue.ElementAt(0) + " " + cityWeatherMetricChar; // Theres more weather data available, but it would just be several // repeats of the above selectors. return(Json(new List <string> { cityLocation.coord.lat.ToString(), cityLocation.coord.lon.ToString(), cityTemperature }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Event method for when the selection within a listbox changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstDataIndex_SelectedIndexChanged(object sender, EventArgs e) { if (this.lstDataIndex.SelectedItem != null) { string title = this.lstDataIndex.SelectedItem.ToString(); object cachedData = this._currentData[title]; this.flpDataContents.Visible = false; this.flpDataContents.Controls.Clear(); Type selectedType = cachedData.GetType(); if (selectedType == typeof(IndexOptionDetail)) { IndexOptionDetail indexOptionDetail = ((IndexOptionDetail)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new IndexOptionDetailControl() { IndexOptionDetail = indexOptionDetail } }); } else if (selectedType == typeof(CountyInfo)) { CountyInfo countyInfo = ((CountyInfo)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new CountyInfoControl() { CountyInfo = countyInfo }, new PictureBox() { Image = this.GetImageFromCounty(countyInfo), SizeMode = PictureBoxSizeMode.AutoSize } }); } else if (selectedType == typeof(CityDetail)) { CityDetail cityDetail = ((CityDetail)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new CityDetailControl() { CityDetail = cityDetail } }); } else if (selectedType == typeof(ProcessQueueDetail)) { ProcessQueueDetail pqDetail = ((ProcessQueueDetail)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new ProcessQueueDetailControl() { ProcessQueueDetail = pqDetail } }); } else if (selectedType == typeof(TitleDetail)) { TitleDetail titleDetail = ((TitleDetail)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new TitleDetailControl() { TitleDetail = titleDetail } }); } else if (selectedType == typeof(RequestingPartyInfo)) { RequestingPartyInfo rpInfo = ((RequestingPartyInfo)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new RequestingPartyInfoControl() { RequestingPartyInfo = rpInfo } }); } else if (selectedType == typeof(SubmittingPartyInfo)) { SubmittingPartyInfo spInfo = ((SubmittingPartyInfo)cachedData); this.flpDataContents.Controls.AddRange(new Control[] { new SubmittingPartyInfoControl() { SubmittingPartyInfo = spInfo } }); } foreach (Control control in this.flpDataContents.Controls) { control.Width = this.flpDataContents.Width - 10; this.RecursiveReadOnlySet(control); } this.flpDataContents.Visible = true; } }