public ValidationState Validate(NoticeType type, out string errorMessage) { var errorBuilder = new StringBuilder(); var isSocial = type.IsSocial(); ValidateGreenCriteria(errorBuilder); ValidateSocialCriteria(errorBuilder); ValidateInnovation(errorBuilder); if (SMEParticipationConsidered == null) { errorBuilder.AppendLine($"{nameof(SMEParticipationConsidered)} is mandatory"); } if (isSocial && EndUserInvolved == null) { errorBuilder.AppendLine($"{nameof(EndUserInvolved)} is mandatory, because {type} is social notice type"); } if (!isSocial && EndUserInvolved != null) { errorBuilder.AppendLine($"{nameof(EndUserInvolved)} is forbidden, because {type} is not social notice type"); } errorMessage = errorBuilder.ToString().Trim(); return(errorMessage.Length > 0 ? ValidationState.Invalid : ValidationState.Valid); }
/// <summary> /// Trims the conditional fields /// </summary> public void Trim(NoticeType type) { var isSocial = type.IsSocial(); if (!AnyGreenOptionSelected()) { ListedGreenCriteriaUsed = null; } if (EmploymentCondition != true) { HowManyOpportunitiesIsEstimated = null; } if (!isSocial) { EndUserInvolved = null; } }