// GET: NearbyPlaces //public async Task<IActionResult> AttitudeSelection() //{ // var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); // var viewer = _context.Viewers.Where(c => c.IdentityUserId == userId).SingleOrDefault(); // var attitudes = _context.Attitude.ToList(); // List<SelectListItem> attitude = attitudes.ConvertAll(a => { // return new SelectListItem() // { // Text = a.AttitudeName, // Value = a.AttitudeId.ToString() // }; // }); // MapViewModel mapView = new MapViewModel() // { // Viewer = viewer, // Attitudes = attitude // }; // return View(mapView); //} public async Task <IActionResult> PlaceSelection() { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var viewer = _context.Viewers.Where(c => c.IdentityUserId == userId).SingleOrDefault(); //var attitude = _context.Attitude.Where(a => a.AttitudeId == id).FirstOrDefault(); var wWID = _context.WWindow.Where(a => a.ViewerLocation.Viewer.ViewerId == viewer.ViewerId).Select(b => b.WWindowId).FirstOrDefault(); var wWindow = _context.WWindow.Where(b => b.WWindowId == wWID).FirstOrDefault(); var vLoc = _context.ViewerLocation.Where(a => a.ViewerLocationViewerId == viewer.ViewerId).FirstOrDefault(); wWindow.ViewerLocation = vLoc; viewer.WWindow = wWindow; var attitudeID = viewer.WWindow.WeekendAttitudeId; var attitude = _context.Attitude.Where(a => a.AttitudeId == attitudeID).FirstOrDefault(); WeatherForecast forecast = await _forecastRequest.GetWeatherForecast(Int32.Parse(viewer.WWindow.ViewerLocation.ViewerLocationZip)); DateTime dt = DateTime.Today; DayOfWeek dw = dt.DayOfWeek; int num = (int)DateTime.Today.DayOfWeek; int num2 = (int)dw; DateTime satNum = DateTime.Today.AddDays(6 - num2); DateTime sunNum = satNum.AddDays(1); string sat = satNum.ToString("yyy-MM-dd", DateTimeFormatInfo.InvariantInfo); string sun = sunNum.ToString("yyy-MM-dd", DateTimeFormatInfo.InvariantInfo); var data = forecast.data.Where(d => (d.valid_date == sat) || (d.valid_date == sun)).ToList(); List <GooglePlaces> googlePlaces; //var googlePlaces = _context.GooglePlacesAttitude.Where(a => a.GooglePlacesAttitudeId == mapView.SelectedAttitude.AttitudeId).Select(b => b.GooglePlaces).ToList(); if (data[0].min_temp > 60 && data[1].min_temp > 60) { //googlePlaces = _context.GooglePlacesAttitude.Where(a => a.GPAAttitudeId == attitude.AttitudeId && a.GooglePlaces.IsOutdoors == true).Select(b => b.GooglePlaces).ToList(); googlePlaces = _context.GooglePlacesAttitude.Where(a => a.GPAAttitudeId == attitude.AttitudeId).Select(b => b.GooglePlaces).ToList(); } else { googlePlaces = _context.GooglePlacesAttitude.Where(a => a.GPAAttitudeId == attitude.AttitudeId && a.GooglePlaces.IsOutdoors == false).Select(b => b.GooglePlaces).ToList(); } List <SelectListItem> places = googlePlaces.ConvertAll(a => { return(new SelectListItem() { Text = a.GooglePlacesDisplay, Value = a.GooglePlacesType }); }); MapViewModel mapView = new MapViewModel() { Viewer = viewer, GooglePlaces = places, SelectedAttitude = attitude }; return(View("PlaceSelection", mapView)); }
// GET: Viewers public async Task<IActionResult> Index() { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var viewerInDb = _context.Viewers.Where(m => m.IdentityUserId == userId).FirstOrDefault(); if (viewerInDb != null) { if (_context.WWindow != null && viewerInDb.WWindow == null) { var wWID = _context.WWindow.Select(b => b.WWindowId).FirstOrDefault(); var wWindow = _context.WWindow.Where(b => b.WWindowId == wWID).FirstOrDefault(); viewerInDb.WWindow = wWindow; _context.SaveChanges(); } //var data = new List<WeatherForecast>(); var viewerZip = Int32.Parse(viewerInDb.ViewerZip); WeatherForecast forecast; if (_context.ViewerLocation != null) { try { if(viewerInDb.WWindow != null) { var vLoc = _context.ViewerLocation.Where(a => a.ViewerLocationViewerId == viewerInDb.ViewerId).FirstOrDefault(); viewerInDb.WWindow.ViewerLocation = vLoc; } else { forecast = await _forecastRequest.GetWeatherForecast(viewerZip); } } catch (NullReferenceException e) when (e.Data == null) { forecast = await _forecastRequest.GetWeatherForecast(viewerZip); } } if (viewerInDb.WWindow == null || viewerInDb.WWindow.ViewerLocation == null || viewerInDb.WWindow.ViewerLocation.ViewerLocationZip == null) { forecast = await _forecastRequest.GetWeatherForecast(viewerZip); } else { forecast = await _forecastRequest.GetWeatherForecast(Int32.Parse(viewerInDb.WWindow.ViewerLocation.ViewerLocationZip)); } DateTime dt = DateTime.Today; DayOfWeek dw = dt.DayOfWeek; int num = (int)DateTime.Today.DayOfWeek; int num2 = (int)dw; DateTime satNum = DateTime.Today.AddDays(6 - num2); DateTime sunNum = satNum.AddDays(1); string sat = satNum.ToString("yyy-MM-dd", DateTimeFormatInfo.InvariantInfo); string sun = sunNum.ToString("yyy-MM-dd", DateTimeFormatInfo.InvariantInfo); var data = forecast.data.Where(d => (d.valid_date == sat) || (d.valid_date == sun)).ToList(); ViewData["City"] = forecast.city_name; ViewData["State"] = forecast.state_code; //Saturday Weather ViewData["SatDate"] = data[0].valid_date; ViewData["SatHighTemp"] = data[0].high_temp; ViewData["SatLowTemp"] = data[0].low_temp; ViewData["SatWindSpeed"] = data[0].wind_spd; ViewData["SatGustsTo"] = data[0].wind_gust_spd; ViewData["SatWindDir"] = data[0].wind_cdir; ViewData["SatSkies"] = data[0].weather.description; //Sunday Weather ViewData["SunDate"] = data[1].valid_date; ViewData["SunHighTemp"] = data[1].high_temp; ViewData["SunLowTemp"] = data[1].low_temp; ViewData["SunWindSpeed"] = data[1].wind_spd; ViewData["SunGustsTo"] = data[1].wind_gust_spd; ViewData["SunWindDir"] = data[1].wind_cdir; ViewData["SunSkies"] = data[1].weather.description; return View(forecast); } else { return RedirectToAction(nameof(Create)); } }