Exemplo n.º 1
0
        //Load role to config
        public async Task <PermissionRoleModel> LoadRolePageFunction()
        {
            var result    = new PermissionRoleModel();
            var lstModule = await Task.Run(() => (from m in _dbConfigContext.AuthorizationModules.AsNoTracking()
                                                  where m.Active == true && m.IsShow == true
                                                  select new PermissionPageFunctionModel
            {
                ModuleId = m.ModuleId,
                ModuleName = m.DisplayName,
                ModuleNameReskey = m.DisplayNameResKey,
                Icon = m.Icon,
                ListPage = (from p in _dbConfigContext.AuthorizationPages.AsNoTracking()
                            where p.Active == true && p.ModuleFid == m.ModuleId
                            select new PageModel
                {
                    PageId = p.PageId,
                    PageName = p.PageName,
                    PageNameResKey = p.PageNameResKey,
                    Icon = p.Icon,
                    ListFunction = (from pf in _dbConfigContext.AuthorizationPageFunctions.AsNoTracking()
                                    join f in _dbConfigContext.AuthorizationFunctions.AsNoTracking() on pf.FunctionId equals f.FuntionId
                                    where pf.PageId == p.PageId
                                    select new FunctionModel
                    {
                        FunctionId = f.FuntionId,
                        FunctionName = f.FunctionName,
                        FunctionNameReskey = f.FunctionNameResKey
                    }).ToList()
                }).ToList()
            }).ToList());

            result.LstModule = lstModule;
            return(result);
        }
Exemplo n.º 2
0
        public ActionResult Access()
        {
            var permissions = _permissionService.GetAllPermission();
            var roles       = _roleService.GetAllRole();

            var model = new PermissionRoleModel();

            var permissionTree = SortPermissionForTree(0);

            model.AvailablePermissions = SortPermissionForTree(permissionTree);

            model.AvailableRoles = roles.Select(t => new RoleModel()
            {
                Id   = t.Id,
                Name = t.Name
            }).ToList();

            //数据库中选中的项目
            foreach (var ps in permissions)
            {
                //checkbox 保存 permission Id
                var key = ps.Id.ToString();
                foreach (var rs in roles)
                {
                    bool allowed = ps.Roles.Count(x => x.Id == rs.Id) > 0;
                    if (!model.Allowed.ContainsKey(key))
                    {
                        model.Allowed[key] = new Dictionary <int, bool>();
                    }

                    model.Allowed[key][rs.Id] = allowed;
                }
            }

            return(View(model));
        }
Exemplo n.º 3
0
 public ActionResult EmployeePermissionRoleUpdate([DataSourceRequest] DataSourceRequest request, PermissionRoleModel dictionary, Guid employeeId)
 {
     if (dictionary != null && ModelState.IsValid)
     {
         var dbEmployeeRole = db.EmployeePermissionRoles.SingleOrDefault(x => x.PermissionRoleId == dictionary.RoleId && x.EmployeeId == employeeId && x.Id != dictionary.EmployeeRoleId);
         if (dbEmployeeRole != null)
         {
             ModelState.AddModelError("Message", Convert.ToString("Роль уже присвоена"));
             return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState)));
         }
         dbEmployeeRole = db.EmployeePermissionRoles.Single(x => x.Id == dictionary.EmployeeRoleId);
         var prevRoleId = dbEmployeeRole.PermissionRoleId;
         dbEmployeeRole.PermissionRoleId = dictionary.RoleId;
         ActionLogger.WriteInt(db, "Обновление сотруднику роли прав доступа", "PrevRoleId: " + prevRoleId + "; CurrentRoleId: " + dictionary.RoleId);
         db.SaveChanges();
         EmployePermissionHelper.ClearEmployeePermission();
     }
     return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState)));
 }
Exemplo n.º 4
0
 public ActionResult EmployeePermissionRoleDestroy([DataSourceRequest] DataSourceRequest request, PermissionRoleModel dictionary, Guid employeeId)
 {
     if (dictionary != null)
     {
         var dbEmployeeRole = db.EmployeePermissionRoles.Single(x => x.Id == dictionary.EmployeeRoleId);
         db.EmployeePermissionRoles.Remove(dbEmployeeRole);
         ActionLogger.WriteInt(db, "Удаление сотруднику роли прав доступа", "RoleId: " + dbEmployeeRole.PermissionRoleId + "; EmployeeId: " + dbEmployeeRole.EmployeeId);
         db.SaveChanges();
         EmployePermissionHelper.ClearEmployeePermission();
     }
     return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState)));
 }
Exemplo n.º 5
0
        public IList <PermissionRoleModel> GetListPermissionRole(string group_code)
        {
            IList <PermissionRoleModel> resp = new List <PermissionRoleModel>();

            try
            {
                using (MSSql mssql = new MSSql(DBConnectionType.RBAC, _EnvironmentModel))
                {
                    string role_code = "";
                    int    seq       = 0;

                    string queryGroup = string.Format(
                        @"SELECT C.code as group_code, C.name_thai as group_name,
                            A.code as role_code, A.name_thai as role_name,
                            (CASE WHEN C.code IS NULL THEN 0 ELSE 1 END) as used
                            FROM [dbo].[SYS_ROLE] A
                            LEFT OUTER JOIN [dbo].[SYS_PERMISSION_ROLE] B
                            ON A.code = B.role_code
                            LEFT OUTER JOIN [dbo].[SYS_USER_GROUP] C
                            ON B.group_code = C.code
                            WHERE C.code='{0}' ",
                        group_code);

                    var dtGroup = mssql.GetDataTableFromQueryStr(queryGroup);

                    if (dtGroup.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtGroup.Rows)
                        {
                            PermissionRoleModel permiss = new PermissionRoleModel()
                            {
                                seq        = seq,
                                group_code = dr["group_code"].ToString(),
                                group_name = dr["group_name"].ToString(),
                                role_code  = dr["role_code"].ToString(),
                                role_name  = dr["role_name"].ToString(),
                                used       = Convert.ToBoolean(dr["used"]),
                            };
                            role_code += string.Format(@"{0}{1}", dr["role_code"].ToString(), ",");
                            seq       += 1;
                            resp.Add(permiss);
                        }
                    }


                    string role_code_array = role_code.Replace(",", "','");

                    string queryUsers = string.Format(
                        @"SELECT NULL as group_code, NULL as group_name, 
                            code as role_code, name_thai as role_name,0 as used
                            FROM [dbo].[SYS_ROLE]
                            WHERE 1=1 {0}",
                        role_code_array.Length > 0 ? " AND code NOT IN ('" + role_code_array.Remove(role_code_array.Length - 3, 3) + "')" : "");

                    var dtUser = mssql.GetDataTableFromQueryStr(queryUsers);

                    if (dtUser.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtUser.Rows)
                        {
                            PermissionRoleModel permiss = new PermissionRoleModel()
                            {
                                seq        = seq,
                                group_code = dr["group_code"].ToString(),
                                group_name = dr["group_name"].ToString(),
                                role_code  = dr["role_code"].ToString(),
                                role_name  = dr["role_name"].ToString(),
                                used       = Convert.ToBoolean(dr["used"]),
                            };
                            seq += 1;
                            resp.Add(permiss);
                        }
                    }

                    return(resp);
                }
            }
            catch (Exception ex)
            {
                _ILogs.LogError("GetList PermissionRole Repository: ", ex.Message.ToString(), ex.StackTrace);
            }
            return(null);
        }