Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["User"] != null && Session["User"].ToString() != string.Empty)
         {
             if (Request.QueryString["id"] == null)
             {
                 if (UserPermissions.Any(
                         p =>
                         p.PageUrl.ToLower().Equals(Common.Members) &&
                         p.ModuleID == (int)ModulesEnum.Committees &&
                         (p.Show.Equals(true) || p.Add.Equals(true) || p.Edit.Equals(true) || p.Delete.Equals(true))))
                 {
                     var per = UserPermissions.FirstOrDefault(
                         p =>
                         p.PageUrl.ToLower().Equals(Common.Members) &&
                         p.ModuleID == (int)ModulesEnum.Committees &&
                         (p.Show.Equals(true) || p.Add.Equals(true) || p.Edit.Equals(true) || p.Delete.Equals(true)));
                     ((HtmlGenericControl)Page.Master.FindControl("ulBreadcrumb")).InnerHtml = "<li><i class='ace-icon fa fa-home home-icon'></i><a href ='Dashboard.aspx'> الرئيسية </a></li><li>" + per.ModuleName + "</li><li>" + per.PageName + "</li><li></li>";
                     Page.Title = per.PageName;
                 }
                 else
                 {
                     Response.Redirect("NoPermission.aspx");
                 }
             }
             else
             {
                 if (UserPermissions.Any(
                         p =>
                         p.PageUrl.ToLower().Equals(Common.Members) &&
                         p.ModuleID == (int)ModulesEnum.CommitteeWorks &&
                         (p.Show.Equals(true) || p.Add.Equals(true) || p.Edit.Equals(true) || p.Delete.Equals(true))))
                 {
                     var per = UserPermissions.FirstOrDefault(
                         p =>
                         p.PageUrl.ToLower().Equals(Common.Members) &&
                         p.ModuleID == (int)ModulesEnum.CommitteeWorks &&
                         (p.Show.Equals(true) || p.Add.Equals(true) || p.Edit.Equals(true) || p.Delete.Equals(true)));
                     ((HtmlGenericControl)Page.Master.FindControl("ulBreadcrumb")).InnerHtml = "<li><i class='ace-icon fa fa-home home-icon'></i><a href ='Dashboard.aspx'> الرئيسية </a></li><li>" + per.ModuleName + "</li><li>" + per.PageName + "</li><li></li>";
                     Page.Title = per.PageName;
                 }
                 else
                 {
                     Response.Redirect("NoPermission.aspx");
                 }
             }
         }
         else
         {
             Session["back"] = Request.Url.AbsoluteUri;
             Response.Redirect("Login.aspx?ReturnURL=" + Request.Url.AbsolutePath);
         }
         BindData();
         BindAttachments();
         BindAwards();
         BindAttendance();
     }
 }
        public bool UserHasPermission(string permissionId)
        {
            bool hasPerm;

            if (_permMap.TryGetValue(permissionId, out hasPerm))
            {
                return(hasPerm);
            }
            hasPerm = UserPermissions.Any(x => x.Id == permissionId);
            _permMap[permissionId] = hasPerm;
            return(hasPerm);
        }
Exemple #3
0
        public override bool IsVisible(ISiteMapNode node, IDictionary <string, object> sourceMetadata)
        {
            //get current user
            UserViewModel CurrentUser = new UserViewModel().GetUserFromSession();
            List <UserRoleServiceAccessViewModel> UserPermissions = new UserRoleServiceAccessModel <UserRoleServiceAccessViewModel>().GetSavedUserPermission();
            string nodeServiceTag = null;

            if (node.Attributes.Keys.Contains("serivceTag"))
            {
                nodeServiceTag = node.Attributes["serivceTag"].ToString();
            }

            bool isVisible = false;
            Guid userId    = new Guid(sourceMetadata["UserId"].ToString());

            if (CurrentUser == null || (userId != null && CurrentUser.UserId != userId))
            {
                CurrentUser = new UserViewModel().GetUserFromSession();
            }

            if (CurrentUser != null) //&& user.EmployeeId != null
            {
                if (UserModel <User> .IsAdmin(CurrentUser))
                {
                    isVisible = true;
                }
                else
                {
                    if (node.Title == "Dashboard")
                    {
                        return(true);
                    }
                    if (UserPermissions == null || (userId != null && CurrentUser.UserId != userId))
                    {
                        UserPermissions = new UserRoleServiceAccessModel <UserRoleServiceAccessViewModel>().GetData(userId: CurrentUser.UserId, fromView: true).ToList();
                    }

                    if (node.HasChildNodes)
                    {
                        //isVisible = true;
                        isVisible = node.ChildNodes.Where(x => x.HasChildNodes == false).Any(x => UserPermissions.Any(y => y.ServiceName == x.Title && y.AccessTypeId == DBEnums.AccessType.View));
                    }
                    else
                    {
                        isVisible = UserPermissions.Any(x => x.ServiceTag == nodeServiceTag && x.AccessTypeId == DBEnums.AccessType.View);
                    }
                }
            }
            return(isVisible);
        }