Esempio n. 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (RequestIsForWhiteListedPage(context))
            {
                await next();

                return;
            }

            var employerAccountId = context.RouteData.Values[RouteValues.EmployerAccountId]?.ToString().ToUpper();
            var userId            = context.HttpContext.User.GetUserId();

            var hasValidCookie          = HasValidLevyCookie(context, employerAccountId);
            var levyControllerRequested = RequestIsForALevyPage(context);

            if (hasValidCookie)
            {
                if (levyControllerRequested)
                {
                    context.Result = new RedirectToRouteResult(RouteNames.Dashboard_Index_Get, new { employerAccountId });
                    return;
                }

                await next();
            }
            else if (await HasStoredDeclaration(employerAccountId, userId))
            {
                if (levyControllerRequested)
                {
                    _levyCookieWriter.WriteCookie(context.HttpContext.Response, userId, employerAccountId);

                    context.Result = new RedirectToRouteResult(RouteNames.Dashboard_Index_Get, new { employerAccountId });
                    return;
                }

                _levyCookieWriter.WriteCookie(context.HttpContext.Response, userId, employerAccountId);

                await next();
            }
            else
            {
                if (!levyControllerRequested)
                {
                    context.Result = new RedirectToRouteResult(RouteNames.LevyDeclaration_Get, new { employerAccountId });
                    return;
                }

                await next();
            }
        }
 private void SetLevyDeclarationCookie(ClaimsPrincipal user, string employerAccountId)
 {
     _levyCookieWriter.WriteCookie(Response, user.GetUserId(), employerAccountId);
 }