示例#1
0
        public async Task <IActionResult> Start()
        {
            var responseId = _clientStorage.Read(SurveyResponse.StorageKey);

            CurrentResponse = await _surveyResponseRepository.Find(responseId);

            if (CurrentResponse == null)
            {
                CurrentResponse = await _surveyResponseRepository.Create();

                _clientStorage.Write(SurveyResponse.StorageKey, CurrentResponse.IdExternal, TimeSpan.FromDays(7));
                await _surveyResponseRepository.SaveChanges();
            }

            return(RedirectToAction("Question1"));
        }
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context.Controller is SurveyController surveyController)
            {
                var responseId = _clientStorage.Read(SurveyResponse.StorageKey);
                surveyController.CurrentResponse = await _surveyResponseRepository.Find(responseId);

                if (surveyController.CurrentResponse == null)
                {
                    _clientStorage.Clear(SurveyResponse.StorageKey);
                    context.Result = new RedirectToRouteResult(
                        new RouteValueDictionary(new { controller = "Home", action = "Index" })
                        );
                    return;
                }
            }

            await next();
        }