public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var existingRelationshipType = HttpRequestStorage.DatabaseEntities.RelationshipTypes.ToList(); if (!RelationshipType.IsRelationshipTypeNameUnique(existingRelationshipType, RelationshipTypeName, RelationshipTypeID)) { yield return(new SitkaValidationResult <EditRelationshipTypeViewModel, string>("Name already exists.", x => x.RelationshipTypeName)); } if (CanStewardProjects == true && existingRelationshipType.Any(x => x.RelationshipTypeID != RelationshipTypeID && x.CanStewardProjects)) { yield return(new SitkaValidationResult <EditRelationshipTypeViewModel, bool?>( $"There can only be one {Models.FieldDefinition.ProjectRelationshipType.GetFieldDefinitionLabel()} in the system where \"Can Steward Projects?\" is set to \"Yes\".", m => m.CanStewardProjects)); } if (IsPrimaryContact == true && existingRelationshipType.Any(x => x.RelationshipTypeID != RelationshipTypeID && x.IsPrimaryContact)) { yield return(new SitkaValidationResult <EditRelationshipTypeViewModel, bool?>( $"There can only be one {Models.FieldDefinition.ProjectRelationshipType.GetFieldDefinitionLabel()} in the system where \"Is Primary Contact?\" is set to \"Yes\".", m => m.IsPrimaryContact)); } }