Ejemplo n.º 1
0
        private static bool CanShow(HtmlHelper htmlHelper, AuthorizationAccountType authAccountType)
        {
            IIdentity userIdentity = htmlHelper.ViewContext.HttpContext.User.Identity;

            if (userIdentity.IsAuthenticated)
            {
                QueryServiceClient queryService = new QueryServiceClient();
                AccountType?       accountType  = queryService.GetAccountType(userIdentity.Name);
                queryService.Close();
                if (accountType != null)
                {
                    bool canShow = false;
                    switch (accountType.Value)
                    {
                    case AccountType.Admin:
                        if ((authAccountType & AuthorizationAccountType.Admin) == AuthorizationAccountType.Admin)
                        {
                            canShow = true;
                        }
                        else
                        {
                            canShow = false;
                        }
                        break;

                    case AccountType.User:
                        if ((authAccountType & AuthorizationAccountType.User) == AuthorizationAccountType.User)
                        {
                            canShow = true;
                        }
                        else
                        {
                            canShow = false;
                        }
                        break;

                    default:
                        break;
                    }
                    return(canShow);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }