Esempio n. 1
0
        private async Task <bool> WasHandledByLevyDeclaration(
            ActionExecutingContext context,
            ActionExecutionDelegate next,
            string userId,
            string employerAccountId,
            bool requestIsForALevyPage)
        {
            bool hasLevyDeclaration = false;

            if (GetCookieValueForUserAndEmployer(
                    context.HttpContext,
                    userId: userId,
                    employerAccountId: employerAccountId,
                    readValue: _levyCookieWriter.GetCookieFromRequest,
                    result: out string hasLevyDeclarationAsString))
            {
                hasLevyDeclaration = bool.Parse(hasLevyDeclarationAsString);
            }
            else
            {
                hasLevyDeclaration = await HasStoredLevyDeclaration(
                    employerAccountId : employerAccountId,
                    userId : userId);

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

            // No Levy declaration = not handled
            if (!hasLevyDeclaration)
            {
                return(false);
            }

            // Don't allow Levy pages if Levy is already declared
            if (requestIsForALevyPage)
            {
                context.Result = new RedirectToRouteResult(RouteNames.Dashboard_Index_Get, new { employerAccountId });
                return(true);
            }

            // Allow pages when Levy declaration is present
            await next();

            return(true);
        }
Esempio n. 2
0
 private void SetLevyDeclarationCookie(ClaimsPrincipal user, string employerAccountId)
 {
     _levyCookieWriter.WriteCookie(Response, user.GetUserId(), employerAccountId, hasLevyDeclaration: true);
 }