public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Command != KeyDatesCommand.ArchiveReference && !NewDate.IsCompleted) { yield return(new ValidationResult(KeyDatesViewModelResources.DateRequiredError, new[] { "NewDate" })); } if (Command == KeyDatesCommand.BeginAssessment) { if (string.IsNullOrWhiteSpace(NameOfOfficer)) { yield return(new ValidationResult(KeyDatesViewModelResources.NameOfOfficerRequiredError, new[] { "NameOfOfficer" })); } else if (NameOfOfficer.Length > 256) { yield return(new ValidationResult(KeyDatesViewModelResources.NameOfOfficerLengthError, new[] { "NameOfOfficer" })); } if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(KeyDatesViewModelResources.CommencementNotInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null) { yield return(new ValidationResult(KeyDatesViewModelResources.CommencementOthersRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime())) { yield return(new ValidationResult(KeyDatesViewModelResources.CommencementNotBeforeOthers, new[] { "NewDate" })); } } if (Command == KeyDatesCommand.NotificationComplete) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(KeyDatesViewModelResources.CompletedNotInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null || PaymentReceivedDate == null) { yield return(new ValidationResult(KeyDatesViewModelResources.CompletedOthersRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) || (PaymentReceivedDate != null && NewDate.AsDateTime() < PaymentReceivedDate)) { yield return(new ValidationResult(KeyDatesViewModelResources.CompletedNotBeforeOthers, new[] { "NewDate" })); } } if (Command == KeyDatesCommand.NotificationAcknowledged) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(KeyDatesViewModelResources.AcknowledgedNotInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null) { yield return(new ValidationResult(KeyDatesViewModelResources.AcknowledgedOthersRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime())) { yield return(new ValidationResult(KeyDatesViewModelResources.AcknowledgedNotBeforeOthers, new[] { "NewDate" })); } } if (Command == KeyDatesCommand.FileClosed) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return (new ValidationResult(KeyDatesViewModelResources.FileClosedInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null) { yield return (new ValidationResult(KeyDatesViewModelResources.FileClosedOtherDatesRequired, new[] { "NewDate" })); } if (NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) { yield return (new ValidationResult(KeyDatesViewModelResources.FileClosedNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesCommand.ArchiveReference) { if (string.IsNullOrWhiteSpace(ArchiveReference)) { yield return (new ValidationResult(KeyDatesViewModelResources.ArchiveReferenceRequired, new[] { "ArchiveReference" })); } else if (ArchiveReference.Length > 100) { yield return (new ValidationResult(KeyDatesViewModelResources.ArchiveReferenceLength, new[] { "ArchiveReference" })); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Command != KeyDatesStatusEnum.ArchiveReference && !NewDate.IsCompleted) { yield return(new ValidationResult("Please enter a valid date", new[] { "NewDate" })); } if (Command == KeyDatesStatusEnum.NotificationReceived) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.ReceivedInFuture, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.AssessmentCommenced) { if (string.IsNullOrWhiteSpace(NameOfOfficer)) { yield return(new ValidationResult(DateInputViewModelResources.NameOfOfficer, new[] { "NameOfOfficer" })); } else if (NameOfOfficer.Count() > 256) { yield return(new ValidationResult(DateInputViewModelResources.NameOfOfficerLength, new[] { "NameOfOfficer" })); } if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.CommencedInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null || PaymentReceivedDate == null) { yield return(new ValidationResult(DateInputViewModelResources.CommencedOtherDatesRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) || (PaymentReceivedDate != null && NewDate.AsDateTime() < PaymentReceivedDate)) { yield return(new ValidationResult(DateInputViewModelResources.CommencedNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.NotificationComplete) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.CompleteInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null || PaymentReceivedDate == null || CommencementDate == null) { yield return(new ValidationResult(DateInputViewModelResources.CompleteOtherDatesRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) || (PaymentReceivedDate != null && NewDate.AsDateTime() < PaymentReceivedDate)) { yield return(new ValidationResult(DateInputViewModelResources.CompleteNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.NotificationTransmitted) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.TransmittedInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null || PaymentReceivedDate == null || CommencementDate == null || NotificationCompleteDate == null) { yield return(new ValidationResult(DateInputViewModelResources.TransmittedOtherDatesRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) || (PaymentReceivedDate != null && NewDate.AsDateTime() < PaymentReceivedDate) || (CommencementDate != null && NewDate.AsDateTime() < CommencementDate.AsDateTime()) || (NotificationCompleteDate != null && NewDate.AsDateTime() < NotificationCompleteDate.AsDateTime())) { yield return(new ValidationResult(DateInputViewModelResources.TransmittedNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.NotificationAcknowledged) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.AcknowledgedInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null || PaymentReceivedDate == null || CommencementDate == null || NotificationCompleteDate == null || NotificationTransmittedDate == null) { yield return(new ValidationResult(DateInputViewModelResources.AcknowledgedOtherDatesRequired, new[] { "NewDate" })); } if ((NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) || (PaymentReceivedDate != null && NewDate.AsDateTime() < PaymentReceivedDate) || (CommencementDate != null && NewDate.AsDateTime() < CommencementDate.AsDateTime()) || (NotificationCompleteDate != null && NewDate.AsDateTime() < NotificationCompleteDate.AsDateTime()) || (NotificationTransmittedDate != null && NewDate.AsDateTime() < NotificationTransmittedDate.AsDateTime())) { yield return(new ValidationResult(DateInputViewModelResources.AcknowledgedNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.FileClosed) { if (NewDate.AsDateTime() > SystemTime.UtcNow) { yield return(new ValidationResult(DateInputViewModelResources.FileClosedInFuture, new[] { "NewDate" })); } if (NotificationReceivedDate == null) { yield return(new ValidationResult(DateInputViewModelResources.CompleteOtherDatesRequired, new[] { "NewDate" })); } if (NotificationReceivedDate != null && NewDate.AsDateTime() < NotificationReceivedDate.AsDateTime()) { yield return(new ValidationResult(DateInputViewModelResources.FileClosedNotBefore, new[] { "NewDate" })); } } if (Command == KeyDatesStatusEnum.ArchiveReference) { if (string.IsNullOrWhiteSpace(ArchiveReference)) { yield return(new ValidationResult(DateInputViewModelResources.ArchiveReferenceRequired, new[] { "ArchiveReference" })); } else if (ArchiveReference.Length > 100) { yield return(new ValidationResult(DateInputViewModelResources.ArchiveReferenceLength, new[] { "ArchiveReference" })); } } }