public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (!IsRoot && !ParentCharacterGroupIds.Any()) { yield return(new ValidationResult("Character group should be part of tree")); } if (IsSpecial) { if (ParentGroups.Any(pg => !pg.IsRoot && !pg.IsSpecial)) { yield return(new ValidationResult("Special group can only be child of root group or another special group")); } } else { if (ParentGroups.Any(pg => pg.IsSpecial)) { yield return(new ValidationResult("Non-special group can't be child of special group")); } if (ParentGroups.Any(pg => pg.CharacterGroupId == CharacterGroupId)) { yield return(new ValidationResult("Character group can't be self-child")); } } }
/// <summary> /// Converts the information of this instance to its equivalent string representation. /// </summary> public override string ToString() { var userStr = string.Join(",", UserMemberIds.Select(x => "U" + x)); var groupStr = string.Join(",", Groups.Select(x => "G" + x.Id)); var parentsStr = string.Join(",", ParentGroups.Select(x => "G" + x.Id)); return("G" + Id + ":" + userStr + ", " + groupStr + "(" + parentsStr + ")"); }