Exemplo n.º 1
0
 public PermissionService()
 {
     _CU_Role_PageService = new CU_Role_PageService();
     _CU_PageService      = new CU_PageService();
     _CU_ActionService    = new CU_ActionService();
     _CU_LogService       = new CU_LogService();
 }
Exemplo n.º 2
0
        public Dictionary <QVEnterprise.ActionType, bool> GetPermission(string currentController, int userID)
        {
            // CU_Employee_RoleService ser = new CU_Employee_RoleService();
            CU_Employee_RoleProgramService ser = new CU_Employee_RoleProgramService();

            var                 Permission  = new Dictionary <QVEnterprise.ActionType, bool>();
            CU_PageService      page        = new CU_PageService();
            List <CU_Role_Page> rolePageLst = new List <CU_Role_Page>();
            CU_Role_PageService rolepage    = new CU_Role_PageService();
            int                 progID      = Extention.GeKeyValue <int>("ProgramID");

            var employeeRolesProgram = ser.GetEmployeeRoleProgram(userID, progID);

            foreach (var role in employeeRolesProgram)
            {
                var rolesPage = rolepage.CU_RolepageList.Where(r => r.IdRoleProgram == role.IdRoleProgram && r.IdPage == page.GetCU_PageByPageURL(currentController).ID).FirstOrDefault();
                if (rolesPage != null)
                {
                    rolePageLst.Add(rolesPage);
                }
            }
            //for each action get max permission allawed in logined user roles
            new CU_ActionService().CU_ActionList.ToList().ForEach(delegate(CU_Action i)
            {
                bool hasPermission = rolePageLst.Where(p => p.Permission.Length > i.Order && p.Permission.Substring(i.Order, 1) == "1").Count() > 0;
                Permission.Add((QVEnterprise.ActionType)System.Enum.Parse(typeof(QVEnterprise.ActionType), i.EnName), hasPermission);
            });
            return(Permission);
        }
Exemplo n.º 3
0
        public Dictionary <string, Dictionary <QVEnterprise.ActionType, bool> > GetPermission(IEnumerable <string> Controllers, int userID)
        {
            // CU_Employee_RoleService ser = new CU_Employee_RoleService();
            CU_Employee_RoleProgramService ser = new CU_Employee_RoleProgramService();

            Dictionary <int, string> pages = new CU_PageService().GetPageIdsByURLs(Controllers);

            //Get all permissions for all pages once and query them when needed instead of querying the database everytime
            Dictionary <string, Dictionary <QVEnterprise.ActionType, bool> > pagesPermissions = new Dictionary <string, Dictionary <QVEnterprise.ActionType, bool> >();


            CU_PageService page = new CU_PageService();

            CU_Role_PageService rolepageservice = new CU_Role_PageService();
            var rolepages = rolepageservice.CU_RolepageList;
            int progID    = Extention.GeKeyValue <int>("ProgramID");

            var actionList = new CU_ActionService().CU_ActionList.ToList();

            var employeeRolesProgram = ser.GetEmployeeRoleProgram(userID, progID);

            foreach (int pageId in pages.Keys)
            {
                List <CU_Role_Page> rolePageLst = new List <CU_Role_Page>();
                var Permission = new Dictionary <QVEnterprise.ActionType, bool>();
                foreach (var role in employeeRolesProgram)
                {
                    var rolesPage = rolepages.Where(r => r.IdRoleProgram == role.IdRoleProgram && pageId == r.IdPage).FirstOrDefault();
                    if (rolesPage != null)
                    {
                        rolePageLst.Add(rolesPage);
                    }
                }
                //for each action get max permission allawed in logined user roles
                actionList.ForEach(delegate(CU_Action i)
                {
                    bool hasPermission = rolePageLst.Where(p => p.Permission.Length > i.Order && p.Permission.Substring(i.Order, 1) == "1").Count() > 0;
                    Permission.Add((QVEnterprise.ActionType)System.Enum.Parse(typeof(QVEnterprise.ActionType), i.EnName), hasPermission);
                });

                //we should not check for this.. but because there are 2 records in the page table having same url :(
                if (!pagesPermissions.ContainsKey(pages[pageId]))
                {
                    pagesPermissions.Add(pages[pageId], Permission);
                }
            }

            return(pagesPermissions);
        }
Exemplo n.º 4
0
        public int[] getUsersByPermissionOnPageAndRole(string strController, ActionType actionType, int RoleID, int SecondRoleID = 0)
        {
            int[] employeeIDs = null;

            int     programID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ProgramID"]);
            CU_Page pageObj   = new CU_PageService().GetCU_PageByPageURL(strController);
            Expression <Func <CU_Employee, bool> > filterExpression = x => (x.CU_Employee_RoleProgram.Any(y => (y.CU_Role_Program.CU_Program.ID == programID) &&
                                                                                                          y.CU_Role_Program.CU_Role_Page.Any() &&
                                                                                                          y.CU_Role_Program.CU_Role_Page.Any(z => z.IdPage == pageObj.ID &&
                                                                                                                                             ((int)actionType - 1 < z.Permission.Length && z.Permission.Substring((int)actionType - 1, 1) == "1"))));

            var employeeList = _CU_EmployeeRepository.GetByFilter(filterExpression).Where(y => y.CU_Employee_RoleProgram.Any(x => x.CU_Role_Program.IdRole == RoleID || x.CU_Role_Program.IdRole == SecondRoleID));

            if (employeeList != null)
            {
                employeeIDs = employeeList.Select(i => i.ID).ToArray();
            }
            return(employeeIDs);
        }