public IActionResult ConfirmVenuePick(string venueId) { WeatherApi weather = new WeatherApi(); var start = (DateTime)TempData["startDate"]; var eveId = (string)TempData["eveId"]; EventVenueViewModel vm = new EventVenueViewModel(); var ven = _context.Venues.Where(x => x.Id == venueId).FirstOrDefault(); var eve = _context.Events.Where(x => x.Id == eveId).FirstOrDefault(); vm.currentVenue = ven; vm.currentEvent = eve; bool withinRange = weather.CheckDateRange(start); if (withinRange == true) { string location = weather.SetRequestString(ven.City, ven.State); var forecast = weather.GetForecast(location); TimeSpan day = start - DateTime.Today; var startForecast = forecast[day.Days]; vm.Forecast = forecast[0].text; int code = forecast[0].code; if (code < 20 || (code > 36 && code < 44) || (code > 44 && code < 48)) { string warning = "Warning, the weather forecast for this venue is poor"; vm.Warning = warning; } } return(View(vm)); }
// GET: Events/Details/5 public async Task <IActionResult> Details(string id) { if (id == null) { return(NotFound()); } var @event = await _context.Events.FirstOrDefaultAsync(m => m.Id == id); if (@event == null) { return(NotFound()); } bool isOrganizer = false; StandardUser organizer = new StandardUser(); var organizerId = _context.EventOrganizers.Where(e => e.EventId == @event.Id).Select(e => e.UserId).Single(); // try catch? organizer = _context.StandardUsers.Where(x => x.ApplicationUserId == organizerId).FirstOrDefault(); if (User.IsInRole("Standard")) { var currentUserId = User.Identity.GetUserId(); var standardUserId = await _context.StandardUsers.Where(u => u.ApplicationUserId == currentUserId).Select(u => u.Id).SingleAsync(); isOrganizer = currentUserId == organizerId; } EventInterestsViewModel eveInterests = new EventInterestsViewModel(); List <Interest> likedInterests = new List <Interest>(); var currentVenue = _context.Venues.Where(x => x.Id == @event.VenueId).FirstOrDefault(); var interestEntries = await _context.EventInterests.Include(v => v.Interests).Where(i => i.EventId == @event.Id).ToListAsync(); foreach (EventInterest i in interestEntries) { likedInterests.Add(i.Interests); } if (currentVenue != null) { WeatherApi weather = new WeatherApi(); bool checkDate = weather.CheckDateRange(@event.StartDate); if (checkDate != false) { string request = weather.SetRequestString(currentVenue.City, currentVenue.State); var forecastData = weather.GetForecast(request); TimeSpan dayIndex = @event.StartDate - DateTime.Today; var forecastDay = forecastData[dayIndex.Days]; eveInterests.Forecast = forecastDay["text"]; } } var participants = GetParticipants(@event.Id); var PCount = ParticipantsCount(@event.Id); eveInterests.Organizer = organizer; eveInterests.Participants = participants; eveInterests.particpantCount = PCount; eveInterests.CurrentVenue = currentVenue; eveInterests.AddedInterests = likedInterests; eveInterests.Interests = likedInterests; eveInterests.CurrentEvent = @event; eveInterests.isOrganizer = isOrganizer; ViewBag.googleMapsKey = ApiKeys.googleMapsKey; return(View(eveInterests)); }