public override void Validate() { base.Validate(); if (!AssignedOperations.Any() && !AssignedRoles.Any()) { throw new NullReferenceException($"Role {Name} must have at least one Operation or Role."); } var notFoundOp = AssignedOperations.FirstOrDefault(i => !Scope.Operations.Contains(i)); if (notFoundOp != null) { throw new InstanceNotFoundException(nameof(Scope.Operations)); } var notFoundRole = AssignedRoles.FirstOrDefault(i => !Scope.AllRoles.Contains(i)); if (notFoundRole != null) { throw new InstanceNotFoundException(nameof(Scope.Roles)); } var cycleAssignedRole = AssignedRoles.FirstOrDefault(i => i == this); if (cycleAssignedRole != null) { throw new NotSupportedException($"Cycle assignment role {cycleAssignedRole.Name}"); } }
private void SaveAssignedOperations() { var currents = AssignOpes; var lastest = AssignedOperations.Select(o => o.Name).ToList(); //Get New Items foreach (var o in lastest.Where(o => !currents.Contains(o))) { IAzTask.AddOperation(o); } //Get Deleted Ones foreach (var o in currents.Where(o => !lastest.Contains(o))) { IAzTask.DeleteOperation(o); } }