public void AddPermission(TypeOfEntity entityNode) { if (entityNode == null) { return; } ObservableTypeOfEntitiesList.Remove(entityNode); UserPermissionNode savedPermission; var foundOriginalPermission = PermissionListViewModel.PermissionsList.OfType <UserPermissionNode>().FirstOrDefault(x => x.TypeOfEntity == entityNode); if (foundOriginalPermission == null) { savedPermission = new UserPermissionNode(); savedPermission.EntityUserOnlyPermission = new EntityUserPermission() { User = user, TypeOfEntity = entityNode }; savedPermission.EntityPermissionExtended = new List <EntityUserPermissionExtended>(); foreach (var item in PermissionListViewModel.PermissionExtensionStore.PermissionExtensions) { var node = new EntityUserPermissionExtended(); node.User = user; node.TypeOfEntity = entityNode; node.PermissionId = item.PermissionId; savedPermission.EntityPermissionExtended.Add(node); } savedPermission.TypeOfEntity = entityNode; PermissionListViewModel.PermissionsList.Add(savedPermission); } else { if (deletePermissionList.Contains(foundOriginalPermission)) { deletePermissionList.Remove(foundOriginalPermission); } savedPermission = foundOriginalPermission; PermissionListViewModel.PermissionsList.Add(savedPermission); } }
public IEnumerable <UserPermissionNode> GetUserAllEntityPermissions(IUnitOfWork uow, int userId, IPermissionExtensionStore permissionExtensionStore) { var entityPermissionList = uow.Session.QueryOver <EntityUserPermission>() .Where(x => x.User.Id == userId) .List(); foreach (var item in entityPermissionList) { var node = new UserPermissionNode(); node.EntityUserOnlyPermission = item; node.TypeOfEntity = item.TypeOfEntity; node.EntityPermissionExtended = new List <EntityUserPermissionExtended>(); foreach (var extension in permissionExtensionStore.PermissionExtensions) { EntityUserPermissionExtended permissionExtendedAlias = null; var permission = uow.Session.QueryOver(() => permissionExtendedAlias) .Where(x => x.User.Id == userId) .And(() => permissionExtendedAlias.PermissionId == extension.PermissionId) .And(x => x.TypeOfEntity.Id == node.TypeOfEntity.Id) .Take(1)?.List()?.FirstOrDefault(); if (permission != null) { node.EntityPermissionExtended.Add(permission); continue; } permission = new EntityUserPermissionExtended(); permission.IsPermissionAvailable = null; permission.PermissionId = extension.PermissionId; permission.User = item.User; permission.TypeOfEntity = item.TypeOfEntity; node.EntityPermissionExtended.Add(permission); } yield return(node); } }