コード例 #1
0
        public async Task <Models.Forecast> GetTodaysWeather(SimplyWeatherLocation location)
        {
            WeatherForecast weatherForecast = await _weatherApi.GetForecast(location);

            if (weatherForecast != null)
            {
                List <HourlyConditions> hourlyConditionsForDay = GetHourlyConditionsForDay(weatherForecast.Hourly);
                Models.Forecast         forecast = new Models.Forecast
                {
                    CurrentTemperature = weatherForecast.Current?.Temp != null ? (int)weatherForecast.Current.Temp : 0,
                    HighTemp           = GetHighTempForDay(hourlyConditionsForDay),
                    LowTemp            = GetLowempForDay(hourlyConditionsForDay),
                    CurrentWindSpeed   = weatherForecast.Current?.WindSpeed != null ? (int)weatherForecast.Current.WindSpeed : 0,
                    FeelsLikeTemp      = weatherForecast.Current?.FeelsLikeTemp != null ? (int)weatherForecast.Current.FeelsLikeTemp : 0,
                };

                if (weatherForecast.Current?.Conditions?.Count > 0)
                {
                    forecast.CurrentConditionsImageUrl = GetUrlForImageIcon(weatherForecast.Current.Conditions[0].Icon);
                    forecast.CurrentConditions         = weatherForecast.Current.Conditions[0].Description;
                }

                forecast.HourlyConditionsForDay = GetHourlyConditions(hourlyConditionsForDay);

                return(forecast);
            }

            return(null);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        // 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));
        }