Esempio n. 1
0
        public JsonResult getWeather(decimal latitude, decimal longitude, string dateCaught, string timeCaught)
        {
            //  https://developer.forecast.io/docs/v2  <-- Weather API Documentation

            DateTime imageDateTime = new DateTime();

            try
            {
                //convert date and time strings
                imageDateTime = Convert.ToDateTime(dateCaught + ' ' + timeCaught);
            }
            catch (Exception ex)
            {
                ErrorLoggingClass errorLog = new ErrorLoggingClass();
                errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "FishController", "getWeather", User.Identity.Name, "dateCaught:" + dateCaught + ", timeCaught:" + timeCaught);
                return(Json(false));
            }

            float lat = (float)latitude;
            float lng = (float)longitude;

            ForecastIORequest request = new ForecastIORequest(_forecastIO_API_Key, lat, lng, imageDateTime, Unit.us, null);
            var response = request.Get();

            FishModels.FishWeather fw = new FishModels.FishWeather();
            fw.current = response.currently;
            fw.daily   = response.daily;
            fw.hourly  = response.hourly;

            //save response to session
            Session["FishWeather"] = fw;

            var result = new {
                temp      = fw.current.temperature,
                feelsLike = fw.current.apparentTemperature,
                icon      = fw.current.icon,
                summary   = fw.current.summary,
                windSpd   = fw.current.windSpeed,
                windDir   = convertBearingToDirection(fw.current.windBearing),
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public bool SaveFishWeather()
        {
            //get Weather Data from session
            FishModels.FishWeather fw = new FishModels.FishWeather();
            fw = (FishModels.FishWeather)HttpContext.Current.Session["FishWeather"];



            try
            {
                // FishDB.saveFishWeather(tons of variables go here...);
                return(true);
            }
            catch (Exception ex)
            {
                error.logError(ex.Message, ex.Source, ex.StackTrace, "saveFishWeather", "DatabaseClass", "saveFishWeather", HttpContext.Current.User.Identity.Name, null);
                return(false);
            }
        }