예제 #1
0
        public PermissionByUserIdModelList SelectPermisionByUserId(UserRequestIdModel userId)
        {
            // userRepository ดึงข้อมูล role id, role name โดย ส่ง user id ไปหา ต้อง join กับ table role ด้วยนะ
            RoleModel     roldInfo      = _userRepository.SelectRoleIdByUserId(userId);
            RoleByIdModel roleByIdModel = new RoleByIdModel();

            roleByIdModel.roleId = roldInfo.id;
            // roleByIdModel.roleId = 1;
            // roleRepository ดึงข้อมูล permision โดยส่ง role id
            List <int> rolePermission = _rolesRepository.SelectRolePermissionByRoleId(roleByIdModel);

            PermissionModelList permission = _rolesRepository.SelectPermissionAll();

            PermissionByUserIdModelList result = new PermissionByUserIdModelList();

            // result.role = "Admin";
            result.role        = roldInfo.role;
            result.permissions = new List <PermissionModel>();

            foreach (PermissionModel item in permission.Permissiontable)
            {
                result.permissions.Add(
                    new PermissionModel()
                {
                    permissionId    = item.permissionId,    //PermisdionTbl
                    permissionName  = item.permissionName,  //PermisdionTbl
                    permissionCheck = rolePermission.IndexOf(item.permissionId) >= 0 ? true : false
                }
                    );
            }

            return(result);
        }
예제 #2
0
 public RoleResponseModel DeleteRoleService(RoleByIdModel requestId)
 {
     try
     {
         RoleResponseModel response = new RoleResponseModel();
         var resRolePermission      = _rolesRepository.DeleteRolePermission(requestId.roleId);
         if (resRolePermission > 0)
         {
             var resRole = _rolesRepository.DeleteRole(requestId.roleId);
             if (resRole > 0)
             {
                 response.success = true;
             }
             else
             {
                 response.success = false;
             }
         }
         else
         {
             response.success = false;
         }
         return(response);
     }
     catch (Exception error)
     {
         Console.WriteLine("Error: " + error);
         return(new RoleResponseModel()
         {
             success = false
         });
     }
 }
예제 #3
0
        public List <int> SelectRolePermissionByRoleId(RoleByIdModel requestId)
        {
            var cs = "Server=localhost\\SQLEXPRESS;Database=HospitalDB;Trusted_Connection=True;";

            using var con = new SqlConnection(cs);
            con.Open();

            string sql = string.Format(@"SELECT PermissionId FROM RolePermissionTbl 
                        WHERE RoleId  = {0}", requestId.roleId);

            using var cmd           = new SqlCommand(sql, con);
            using SqlDataReader rdr = cmd.ExecuteReader();

            List <int> output = new List <int>();

            while (rdr.Read())
            {
                output.Add(
                    rdr.GetInt32(0)
                    );
            }
            return(output);
        }
예제 #4
0
        public PermissionByIdModelList SelectPermissionsById(RoleByIdModel requestId)
        {
            List <int>          rolePermission = _rolesRepository.SelectRolePermissionByRoleId(requestId);
            PermissionModelList permission     = _rolesRepository.SelectPermissionAll();

            PermissionByIdModelList result = new PermissionByIdModelList();

            result.PermissionIdList = new List <PermissionModel>();

            foreach (PermissionModel item in permission.Permissiontable)
            {
                result.PermissionIdList.Add(
                    new PermissionModel()
                {
                    permissionId    = item.permissionId,   //PermisdionTbl
                    permissionName  = item.permissionName, //PermisdionTbl
                    permissionCheck = rolePermission.IndexOf(item.permissionId) >= 0 ? true : false
                                                           //Search PermissionId(PermissionTbl) on RolePermisdion(RolePermissionTbl)
                }
                    );
            }

            return(result);
        }
예제 #5
0
        public RoleResponseModel DeleteRole([FromQuery] RoleByIdModel requestId)
        {
            RoleResponseModel result = _rolesService.DeleteRoleService(requestId);

            return(result);
        }
예제 #6
0
        public PermissionByIdModelList GetPermissionListById([FromQuery] RoleByIdModel requestId)
        {
            PermissionByIdModelList result = _rolesService.SelectPermissionsById(requestId);

            return(result);
        }