hi, i want to get all parent permissions with childs to create permission tree by jstree.
this is my code in permissionAppService:
public virtual List<PermissionListDto> GetAllPermissionList()
{
var permissions = _permissionManager.GetAllPermissions(true).Where(a=>a.Parent==null).ToList();
return permissions.MapTo<List<PermissionListDto>>();
}
and my PermissionListDto:
[AutoMapFrom(typeof(Permission))]
public class PermissionListDto
{
public virtual ICollection<PermissionListDto> Children { get; }
public virtual string Description { get; set; }
public virtual string DisplayName { get; set; }
public virtual string Name { get; set; }
public virtual string Text { get; set; }
public virtual PermissionListDto Parent { get; set; }
}
but when i call my function in javacsript, i get this error in browser console:
There is an action GetAllPermissionList defined for api controller app/permission but with a different HTTP Verb. Request verb is GET. It should be Post
i think that, automap from IReadonlylist to ICollection (for childrens) is the problem, but i dont khnow how to solve it. please help me, :cry:
4 Answer(s)
-
0
Hi,
According to error message your making a GET reuqest. You should make a POST request.
How do you call this GetAllPermissionList from client side ?
-
0
hi and thank you for reply. i solve this error.
but i have another problem. in PermissionAppService i want to load only parent permissions with childrens of this parents.
and i write this code:
var permissions = _permissionManager.GetAllPermissions(true).Where(a=>a.Parent==null).ToList();
when i write this where condition, only parent permissions returned, but childrens of parent permissions are null and does not load. and when i remove where condition,all parents and childerens are load together and my program display incorrect tree. how can i solve this problem?
-
0
Hi,
You can get all permissions and parent permissions like this.
var permissions = PermissionManager.GetAllPermissions(); var rootPermissions = permissions.Where(p => p.Parent == null);
Then you can fill child permissions using a recursive method like this.
foreach (var rootPermission in rootPermissions) { AddChildPermission(rootPermission, permissions); }
void AddChildPermission(...) { ..... }
-
0
Hi,
In AddChildPermission when you say fill children do you mean rootPermission.CreateChildPermission or something else? Am sorry having a hard time trying to populate the children. This is what i have so far:
public List<PermissionListDto> GetPermissions() { var permissions = PermissionManager.GetAllPermissions(); var rootPermissions = permissions.Where(p => p.Parent == null); foreach (var rootPermission in rootPermissions) { AddChildPermission(rootPermission, permissions); } List<PermissionListDto> retValue = rootPermissions.MapTo<List<PermissionListDto>>(); return retValue; } private void AddChildPermission(Permission rootPermission, IReadOnlyList<Permission> permissions) { foreach(var child in rootPermission.Children) { //dont know what to do in here } }