Controller used in mobile app
Inheritance: ControllerBase
コード例 #1
0
        public JsonResult GetForecast(ForecastRetrieveDTO forecastDTO)
        {
            GenericResponse responseObj = null;
            int             timeStart   = DateTime.Now.TimeOfDay.Seconds;

            try
            {
                string userName = new AuthWorker(Options.OAuthUrl, Options.OAuthRedirectUrl, Options.OAuthSecret,
                                                 Options.OAuthAppId).GetUserInfo(forecastDTO.authToken).username;
                if (userName == null)
                {
                    throw new Sequencing.WeatherApp.Controllers.DaoLayer.ApplicationException(string.Format("Invalid access token {0}", forecastDTO.authToken));
                }

                AppChainResults acr = new AppChainResults
                {
                    MelanomaAppChainResult = forecastDTO.melanomaRisk,
                    VitDAppChainResult     = forecastDTO.vitaminD
                };

                var _s = new PersonalizedRecommendationsWorker().GetRecommendation(forecastDTO.forecastRequest, acr, userName, forecastDTO.appId);

                responseObj = new GenericResponse()
                {
                    Status       = 0,
                    ResponseTime = DateTime.Now.TimeOfDay.Seconds - timeStart,
                    Message      = "Genetically tailored forecast successfully retrieved",
                    Data         = _s,
                };

                return(Json(responseObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                responseObj = new GenericResponse()
                {
                    Status       = 1,
                    ResponseTime = DateTime.Now.TimeOfDay.Milliseconds - timeStart,
                    Message      = e.Message,
                    Data         = "Personalization is not possible due to insufficient genetic data in the selected file. Choose a different genetic data file.",
                };

                ExternalSettingsController.ResponseLogging(responseObj);
                return(Json(responseObj, JsonRequestBehavior.AllowGet));
            }
        }