Exemple #1
0
        }//end function IsAuthenticated

        public static bool IsAllowed(string Role, string MenuName, string MenuGroupName)
        {
            IUserAccountService _userAccountService = new UserAccountService(new UserAccountRepository(), new UserAccountValidator());
            IUserAccessService  _userAccessService  = new UserAccessService(new UserAccessRepository(), new UserAccessValidator());
            IUserMenuService    _userMenuService    = new UserMenuService(new UserMenuRepository(), new UserMenuValidator());

            UserAccount userAccount = _userAccountService.GetObjectById(GetUserId());

            if (userAccount == null)
            {
                return(false);
            }
            if (userAccount.IsAdmin)
            {
                return(true);
            }
            UserMenu userMenu = _userMenuService.GetObjectByNameAndGroupName(MenuName, MenuGroupName);

            if (userMenu != null)
            {
                UserAccess userAccess = _userAccessService.GetObjectByUserAccountIdAndUserMenuId(userAccount.Id, userMenu.Id);
                if (userAccess != null)
                {
                    switch (Role.ToLower())
                    {
                    case "manualpricing": return(userAccess.AllowSpecialPricing);

                    case "view": return(userAccess.AllowView);

                    case "create": return(userAccess.AllowCreate);

                    case "edit": return(userAccess.AllowEdit);

                    case "delete": return(userAccess.AllowDelete);

                    case "undelete": return(userAccess.AllowUndelete);

                    case "confirm": return(userAccess.AllowConfirm);

                    case "unconfirm": return(userAccess.AllowUnconfirm);

                    case "paid": return(userAccess.AllowPaid);

                    case "unpaid": return(userAccess.AllowUnpaid);

                    case "reconcile": return(userAccess.AllowReconcile);

                    case "unreconcile": return(userAccess.AllowUnreconcile);

                    case "print": return(userAccess.AllowPrint);
                    }
                }
            }
            return(false);
        }//end function IsAllowed