public async Task <bool> DeleteRole(RoleNode roleNode, IList list)
        {
            var result = await authorisationManagerServiceProxy.DeleteRole(roleNode.Id);

            if (result)
            {
                list.RemoveNested(roleNode, r => r.Id.Equals(roleNode.Id));
            }

            return(result);
        }
Esempio n. 2
0
        public void AddRole(RoleNode role)
        {
            if (!Roles.Any(r => r.Id.Equals(role.Id)))
            {
                var clone = role.DeepClone();
                clone.ParentId   = Id;
                clone.ParentType = ParentType.UserNode;

                Roles.Add(clone);

                if (!UserAuthorisation.Roles.Any(r => r.Id.Equals(role.Id)))
                {
                    UserAuthorisation.Roles.Add(clone.Role);
                }
            }
        }
Esempio n. 3
0
        public void AddRole(RoleNode role)
        {
            if (!Roles.Any(r => r.Id.Equals(role.Id)))
            {
                var clone = role.DeepClone();
                clone.ParentType = ParentType.RoleNode;
                clone.ParentId   = Id;

                Roles.Add(clone);

                if (!Role.Roles.Any(r => r.Id.Equals(role.Id)))
                {
                    Role.Roles.Add(clone.Role);
                }
            }
        }
        public void AddRole(RoleNode role)
        {
            if (!Roles.Any(r => r.Id.Equals(role.Id)))
            {
                var clone = role.DeepClone();
                clone.ParentId = Id;
                clone.ParentType = ParentType.UserNode;

                Roles.Add(clone);

                if (!UserAuthorisation.Roles.Any(r => r.Id.Equals(role.Id)))
                {
                    UserAuthorisation.Roles.Add(clone.Role);
                }
            }
        }
        public async Task <bool> AddActivity(ActivityNode activityNode, RoleNode targetRoleNode, IEnumerable <RoleNode> targets)
        {
            var result = await authorisationManagerServiceProxy.AddActivityToRole(targetRoleNode.Id, activityNode.Id);

            if (result)
            {
                foreach (var role in targets)
                {
                    if (role.Activities.All(a => a.Id != activityNode.Id))
                    {
                        role.AddActivity(activityNode);
                    }
                }
            }

            return(result);
        }
        public async Task <bool> AddRole(RoleNode roleNode, UserNode targetUserNode, IEnumerable <UserNode> targets)
        {
            var result = await authorisationManagerServiceProxy.AddRoleToUser(targetUserNode.Id, roleNode.Id);

            if (result)
            {
                foreach (var user in targets)
                {
                    if (user.Roles.All(r => r.Id != roleNode.Id))
                    {
                        user.AddRole(roleNode);
                    }
                }
            }

            return(result);
        }
        public async Task <bool> RemoveRoleFromRole(RoleNode roleNode, IList <RoleNode> roles)
        {
            if (roleNode.ParentType == ParentType.RoleNode)
            {
                var result = await authorisationManagerServiceProxy.RemoveRoleFromRole(roleNode.Id, roleNode.ParentId);

                if (result)
                {
                    var parentRoles = roles.Where(r => r.Id.Equals(roleNode.ParentId));
                    foreach (var role in parentRoles)
                    {
                        role.RemoveRole(roleNode.Id);
                    }
                }

                return(result);
            }

            return(false);
        }
        public async Task <bool> RemoveRoleFromUser(RoleNode roleNode, IList <UserNode> users)
        {
            if (roleNode.ParentType == ParentType.UserNode)
            {
                var result = await authorisationManagerServiceProxy.RemoveRoleFromUser(roleNode.Id, roleNode.ParentId);

                if (result)
                {
                    var parentUsers = users.Where(u => u.Id.Equals(roleNode.ParentId));
                    foreach (var parent in parentUsers)
                    {
                        parent.RemoveRole(roleNode.Id);
                    }
                }

                return(result);
            }

            return(false);
        }
        public async Task<RoleNode> SaveRole(RoleNode roleNode, IEnumerable<RoleNode> roles)
        {
            var role = await authorisationManagerServiceProxy.SaveRole(roleNode.Role).ConfigureAwait(false);
            var savedRoleNode = GetRoleNode(role);

            if (roleNode.Id.Equals(0))
            {
                roleNode.Id = savedRoleNode.Id;
                roleNode.Text = savedRoleNode.Text;
                roleNode.Code = savedRoleNode.Code;
                roleNode.Description = savedRoleNode.Description;
            }

            foreach (var r in roles)
            {
                r.Text = savedRoleNode.Text;
                r.Code = savedRoleNode.Code;
                r.Description = savedRoleNode.Description;                
            }

            return roleNode;
        }
        private RoleNode GetRoleNode(Role role)
        {
            var roleNode = new RoleNode(role);

            role.Activities.ToList().ForEach(a =>
            {
                var an        = GetActivityNode(a);
                an.ParentId   = role.Id;
                an.ParentType = ParentType.RoleNode;

                roleNode.Activities.Add(an);
            });
            role.Roles.ToList().ForEach(r =>
            {
                var rn        = GetRoleNode(r);
                rn.ParentId   = role.Id;
                rn.ParentType = ParentType.RoleNode;

                roleNode.Roles.Add(rn);
            });
            return(roleNode);
        }
        public async Task <RoleNode> SaveRole(RoleNode roleNode, IEnumerable <RoleNode> roles)
        {
            var role = await authorisationManagerServiceProxy.SaveRole(roleNode.Role).ConfigureAwait(false);

            var savedRoleNode = GetRoleNode(role);

            if (roleNode.Id.Equals(0))
            {
                roleNode.Id          = savedRoleNode.Id;
                roleNode.Text        = savedRoleNode.Text;
                roleNode.Code        = savedRoleNode.Code;
                roleNode.Description = savedRoleNode.Description;
            }

            foreach (var r in roles)
            {
                r.Text        = savedRoleNode.Text;
                r.Code        = savedRoleNode.Code;
                r.Description = savedRoleNode.Description;
            }

            return(roleNode);
        }
        private async void AddRole(RoleNode roleNode, NodeEntityBase target)
        {
            try
            {
                IsBusy = true;

                if (AuthorisationManagerServiceManager.TargetNodeIsDropCandidate(target, roleNode))
                {
                    return;
                }

                if (target is RoleNode)
                {
                    var targets = Roles.Flatten<RoleNode>(t => t.Id.Equals(target.Id), Users);
                    var result = await authorisationManagerServiceManager.AddRole(roleNode, (RoleNode) target, targets);
                }
                else if (target is UserNode)
                {
                    var targets = Users.Where(t => t.Id.Equals(target.Id));
                    var result = await authorisationManagerServiceManager.AddRole(roleNode, (UserNode) target, targets);
                }
                else
                {
                    throw new Exception(
                        string.Format(
                            "Invalid drop target. '{0}' can only be dropped onto a user or another role.",
                            roleNode.Text));
                }

                ResetStatus();
            }
            catch (Exception ex)
            {
                ShowMessage(new Message()
                {
                    MessageType = MessageTypeEnum.Error,
                    Text = ex.Message
                }, true);

                IsBusy = false;
            }
            finally
            {
                OnPropertyChanged("");
            }
        }
        private async void SaveRole(RoleNode roleNode)
        {
            try
            {
                IsBusy = true;

                var newRole = roleNode.Id.Equals(0);

                var duplicateRoles = Roles.Flatten<RoleNode>(r => r.Id.Equals(roleNode.Id), Users);

                var savedRole = await authorisationManagerServiceManager.SaveRole(roleNode, duplicateRoles);

                if (savedRole != null)
                {
                    if (newRole)
                    {
                        Roles.Add(roleNode);
                    }
                }

                ResetStatus();
            }
            catch (Exception ex)
            {
                ShowMessage(new Message()
                {
                    MessageType = MessageTypeEnum.Error,
                    Text = ex.Message
                }, true);

                IsBusy = false;
            }
            finally
            {
                OnPropertyChanged("");
            }
        }
        public async Task<bool> RemoveRoleFromUser(RoleNode roleNode, IList<UserNode> users)
        {
            if (roleNode.ParentType == ParentType.UserNode)
            {
                var result = await authorisationManagerServiceProxy.RemoveRoleFromUser(roleNode.Id, roleNode.ParentId);
                if (result)
                {
                    var parentUsers = users.Where(u => u.Id.Equals(roleNode.ParentId));
                    foreach (var parent in parentUsers)
                    {
                        parent.RemoveRole(roleNode.Id);
                    }
                }

                return result;
            }

            return false;
        }
        public async Task<bool> AddActivity(ActivityNode activityNode, RoleNode targetRoleNode, IEnumerable<RoleNode> targets)
        {
            var result = await authorisationManagerServiceProxy.AddActivityToRole(targetRoleNode.Id, activityNode.Id);
            if (result)
            {
                foreach (var role in targets)
                {
                    if (role.Activities.All(a => a.Id != activityNode.Id))
                    {
                        role.AddActivity(activityNode);
                    }
                }
            }

            return result;
        }
        public async Task<bool> AddRole(RoleNode roleNode, UserNode targetUserNode, IEnumerable<UserNode> targets)
        {
            var result = await authorisationManagerServiceProxy.AddRoleToUser(targetUserNode.Id, roleNode.Id);
            if (result)
            {
                foreach (var user in targets)
                {
                    if (user.Roles.All(r => r.Id != roleNode.Id))
                    {
                        user.AddRole(roleNode);
                    }
                }
            }

            return result;
        }
        private RoleNode GetRoleNode(Role role)
        {
            var roleNode = new RoleNode(role);
            role.Activities.ToList().ForEach(a =>
            {
                var an = GetActivityNode(a);
                an.ParentId = role.Id;
                an.ParentType = ParentType.RoleNode;

                roleNode.Activities.Add(an);
            });
            role.Roles.ToList().ForEach(r =>
            {
                var rn = GetRoleNode(r);
                rn.ParentId = role.Id;
                rn.ParentType = ParentType.RoleNode;

                roleNode.Roles.Add(rn);
            });
            return roleNode;
        }
        public async Task<bool> RemoveRoleFromRole(RoleNode roleNode, IList<RoleNode> roles)
        {
            if (roleNode.ParentType == ParentType.RoleNode)
            {
                var result = await authorisationManagerServiceProxy.RemoveRoleFromRole(roleNode.Id, roleNode.ParentId);
                if (result)
                {
                    var parentRoles = roles.Where(r => r.Id.Equals(roleNode.ParentId));
                    foreach (var role in parentRoles)
                    {
                        role.RemoveRole(roleNode.Id);
                    }
                }

                return result;
            }

            return false;
        }
        private async void RemoveRole(RoleNode roleNode)
        {
            if (roleNode.ParentType == ParentType.None)
            {
                ShowMessage(new Message()
                {
                    MessageType = MessageTypeEnum.Warn,
                    Text = string.Format("Can't remove role {0} as it has no parent.", roleNode.Text)
                }, true);
                return;
            }

            try
            {
                IsBusy = true;

                if (roleNode.ParentType == ParentType.RoleNode)
                {
                    var roles = Roles.Flatten<RoleNode>(Users).ToList();
                    var result = await authorisationManagerServiceManager.RemoveRoleFromRole(roleNode, roles);
                }
                else if (roleNode.ParentType == ParentType.UserNode)
                {
                    var users = Users.Flatten<UserNode>().ToList();
                    var result = await authorisationManagerServiceManager.RemoveRoleFromUser(roleNode, users);
                }

                ResetStatus();
            }
            catch (Exception ex)
            {
                ShowMessage(new Message()
                {
                    MessageType = MessageTypeEnum.Error,
                    Text = ex.Message
                }, true);

                IsBusy = false;
            }
            finally
            {
                OnPropertyChanged("");
            }
        }
Esempio n. 20
0
        public void AddRole(RoleNode role)
        {
            if (!Roles.Any(r => r.Id.Equals(role.Id)))
            {
                var clone = role.DeepClone();
                clone.ParentType = ParentType.RoleNode;
                clone.ParentId = Id;

                Roles.Add(clone);

                if (!Role.Roles.Any(r => r.Id.Equals(role.Id)))
                {
                    Role.Roles.Add(clone.Role);
                }
            }
        }
        private async void DeleteRole(RoleNode roleNode)
        {
            try
            {
                IsBusy = true;
                var aggregatedList = Roles.Merge(Users);
                var result = await authorisationManagerServiceManager.DeleteRole(roleNode, aggregatedList);
                SelectedItem = null;
                ResetStatus();
            }
            catch (Exception ex)
            {
                ShowMessage(new Message()
                {
                    MessageType = MessageTypeEnum.Error,
                    Text = ex.Message
                }, true);

                IsBusy = false;
            }
            finally
            {
                OnPropertyChanged("");
            }
        }
        public async Task<bool> DeleteRole(RoleNode roleNode, IList list)
        {
            var result = await authorisationManagerServiceProxy.DeleteRole(roleNode.Id);
            if (result)
            {
                list.RemoveNested(roleNode, r => r.Id.Equals(roleNode.Id));
            }

            return result;
        }