public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (ProjectExemptReportingYearUpdates != null && ProjectExemptReportingYearUpdates.Any(x => x.IsExempt) && string.IsNullOrWhiteSpace(Explanation))
     {
         yield return(new SitkaValidationResult <ReportedPerformanceMeasuresViewModel, string>(
                          FirmaValidationMessages.ExplanationNecessaryForProjectExemptYears, x => x.Explanation));
     }
     if (!string.IsNullOrWhiteSpace(Explanation) && Explanation.Length > ProjectUpdateBatch.FieldLengths.PerformanceMeasureActualYearsExemptionExplanation)
     {
         yield return(new SitkaValidationResult <ReportedPerformanceMeasuresViewModel, string>(
                          FirmaValidationMessages.ExplanationForProjectExemptYearsExceedsMax(ProjectUpdateBatch.FieldLengths.PerformanceMeasureActualYearsExemptionExplanation), x => x.Explanation));
     }
 }
Beispiel #2
0
        private PartialViewResult ViewEditPerformanceMeasureActuals(Project project, EditPerformanceMeasureActualsViewModel viewModel)
        {
            var performanceMeasures = PerformanceMeasureModelExtensions.GetReportablePerformanceMeasures().ToList().SortByOrderThenName().ToList();
            var showExemptYears     = project.GetPerformanceMeasuresExemptReportingYears().Any() ||
                                      ModelState.Values.SelectMany(x => x.Errors)
                                      .Any(
                x =>
                x.ErrorMessage == FirmaValidationMessages.ExplanationNotNecessaryForProjectExemptYears ||
                x.ErrorMessage == FirmaValidationMessages.ExplanationNecessaryForProjectExemptYears ||
                x.ErrorMessage == FirmaValidationMessages.ExplanationForProjectExemptYearsExceedsMax(Project.FieldLengths.PerformanceMeasureActualYearsExemptionExplanation) ||
                x.ErrorMessage == FirmaValidationMessages.PerformanceMeasureOrExemptYearsRequired);
            var viewData = new EditPerformanceMeasureActualsViewData(project, performanceMeasures, showExemptYears);

            return(RazorPartialView <EditPerformanceMeasureActuals, EditPerformanceMeasureActualsViewData, EditPerformanceMeasureActualsViewModel>(viewData, viewModel));
        }
        public IEnumerable <ValidationResult> GetValidationResults()
        {
            var errors = new List <ValidationResult>();

            if (ProjectExemptReportingYearSimples != null && ProjectExemptReportingYearSimples.Any(x => x.IsExempt) && string.IsNullOrWhiteSpace(Explanation))
            {
                errors.Add(new SitkaValidationResult <PerformanceMeasuresViewModel, string>(FirmaValidationMessages.ExplanationNecessaryForProjectExemptYears, x => x.Explanation));
            }
            if (!string.IsNullOrWhiteSpace(Explanation) && Explanation.Length > ProjectFirmaModels.Models.Project.FieldLengths.PerformanceMeasureActualYearsExemptionExplanation)
            {
                errors.Add(new SitkaValidationResult <PerformanceMeasuresViewModel, string>(
                               FirmaValidationMessages.ExplanationForProjectExemptYearsExceedsMax(ProjectFirmaModels.Models.Project.FieldLengths.PerformanceMeasureActualYearsExemptionExplanation),
                               x => x.Explanation));
            }

            var pmValidationResults = ValidatePerformanceMeasures();
            var allWarningMessages  = pmValidationResults.SelectMany(pmvr => pmvr.GetWarningMessages());

            errors.AddRange(allWarningMessages.Select(m => new ValidationResult(m)));

            return(errors);
        }