Пример #1
0
        public static bool IsPassingAllValidationRules(this ProjectUpdateBatch projectUpdateBatch)
        {
            bool areAllProjectGeospatialAreasValid = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes.ToList().All(geospatialAreaType => projectUpdateBatch.IsProjectGeospatialAreaValid(geospatialAreaType));

            return(projectUpdateBatch.AreProjectBasicsValid() &&
                   projectUpdateBatch.AreContactsValid() &&
                   projectUpdateBatch.AreExpendituresValid() &&
                   projectUpdateBatch.AreReportedPerformanceMeasuresValid() &&
                   projectUpdateBatch.IsProjectLocationSimpleValid() &&
                   projectUpdateBatch.AreProjectCustomAttributesValid(HttpRequestStorage.FirmaSession) &&
                   areAllProjectGeospatialAreasValid);
        }
        public static bool IsPassingAllValidationRules(this ProjectUpdateBatch projectUpdateBatch)
        {
            bool areAllProjectGeospatialAreasValid = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes.ToList().All(geospatialAreaType => projectUpdateBatch.IsProjectGeospatialAreaValid(geospatialAreaType));

            // 4/17/20 TK - We removed the ability to edit expenditures. No longer need to check for valid on them.
            // 5/28/2020 - SLG leaving in expenditures line for now to aid merges. We'll see if it helps.
            return(projectUpdateBatch.AreProjectBasicsValid() &&
                   projectUpdateBatch.AreContactsValid() &&
                   //projectUpdateBatch.AreExpendituresValid() &&
                   projectUpdateBatch.AreReportedPerformanceMeasuresValid() &&
                   projectUpdateBatch.IsProjectLocationSimpleValid() &&
                   projectUpdateBatch.AreProjectCustomAttributesValid(HttpRequestStorage.FirmaSession) &&
                   areAllProjectGeospatialAreasValid);
        }
Пример #3
0
        public static List <string> ValidateExpenditures(this ProjectUpdateBatch projectUpdateBatch)
        {
            if (!projectUpdateBatch.AreProjectBasicsValid())
            {
                return(new List <string> {
                    FirmaValidationMessages.UpdateSectionIsDependentUponBasicsSection
                });
            }

            if (projectUpdateBatch.ProjectUpdate.ProjectStage.RequiresReportedExpenditures() || projectUpdateBatch.ProjectUpdate.ProjectStage == ProjectStage.Completed)
            {
                // validation 1: ensure that we have expenditure values from ProjectUpdate start year to min(endyear, currentyear)
                var yearsExpected        = projectUpdateBatch.ProjectUpdate.GetProjectUpdatePlanningDesignStartToCompletionYearRange();
                var validateExpenditures = ExpendituresValidationResult.ValidateImpl(projectUpdateBatch.ExpendituresNote, yearsExpected, new List <IFundingSourceExpenditure>(projectUpdateBatch.ProjectFundingSourceExpenditureUpdates));
                return(validateExpenditures);
            }
            return(new List <string>());
        }
        public static bool IsComplete(this ProjectUpdateSection projectUpdateSection, ProjectUpdateBatch projectUpdateBatch)
        {
            if (projectUpdateBatch == null)
            {
                return(false);
            }

            var currentFirmaSession = HttpRequestStorage.FirmaSession;

            switch (projectUpdateSection.ToEnum)
            {
            case ProjectUpdateSectionEnum.Basics:
                return(projectUpdateBatch.AreProjectBasicsValid());

            case ProjectUpdateSectionEnum.CustomAttributes:
                return(projectUpdateBatch.AreProjectCustomAttributesValid(currentFirmaSession));

            case ProjectUpdateSectionEnum.LocationSimple:
                return(projectUpdateBatch.IsProjectLocationSimpleValid());

            case ProjectUpdateSectionEnum.Organizations:
                return(projectUpdateBatch.AreOrganizationsValid());

            case ProjectUpdateSectionEnum.Contacts:
                return(projectUpdateBatch.AreContactsValid());

            case ProjectUpdateSectionEnum.LocationDetailed:
                return(true);

            case ProjectUpdateSectionEnum.ReportedAccomplishments:
                return(projectUpdateBatch.AreReportedPerformanceMeasuresValid());

            case ProjectUpdateSectionEnum.Budget:
                return(true);

            //case ProjectUpdateSectionEnum.Expenditures:
            //    return projectUpdateBatch.AreExpendituresValid();
            case ProjectUpdateSectionEnum.Photos:
                return(true);

            case ProjectUpdateSectionEnum.ExternalLinks:
                return(true);

            case ProjectUpdateSectionEnum.AttachmentsAndNotes:
                return(true);

            case ProjectUpdateSectionEnum.ExpectedAccomplishments:
                return(true);

            case ProjectUpdateSectionEnum.TechnicalAssistanceRequests:
                return(true);

            case ProjectUpdateSectionEnum.BulkSetSpatialInformation:
                return(true);

            case ProjectUpdateSectionEnum.PartnerFinder:
                return(true);

            case ProjectUpdateSectionEnum.Classifications:
                return(projectUpdateBatch.ValidateClassifications().IsValid);

            default:
                throw new ArgumentOutOfRangeException($"IsComplete(): Unhandled Project Update Section Enum: {projectUpdateSection.ToEnum}");
            }
        }
Пример #5
0
        public static List <string> ValidateExpendituresByCostType(this ProjectUpdateBatch projectUpdateBatch)
        {
            if (!projectUpdateBatch.AreProjectBasicsValid())
            {
                return(new List <string> {
                    FirmaValidationMessages.UpdateSectionIsDependentUponBasicsSection
                });
            }

            if (projectUpdateBatch.ProjectUpdate.ProjectStage.RequiresReportedExpenditures() || projectUpdateBatch.ProjectUpdate.ProjectStage == ProjectStage.Completed)
            {
                // validation 1: ensure that we have expenditure values from ProjectUpdate start year to min(endyear, currentyear)
                var yearsExpected = projectUpdateBatch.ProjectUpdate.GetProjectUpdatePlanningDesignStartToCompletionYearRange();
                List <IFundingSourceExpenditure> projectFundingSourceExpenditures = new List <IFundingSourceExpenditure>(projectUpdateBatch.ProjectFundingSourceExpenditureUpdates);
                var errors = new List <string>();
                // Need to get FundingSources by IDs because we may have unsaved projectFundingSourceExpenditures that won't have a reference to the entity
                var fundingSourcesIDs = projectFundingSourceExpenditures.Select(x => x.FundingSourceID).Distinct().ToList();
                var fundingSources    =
                    HttpRequestStorage.DatabaseEntities.FundingSources.Where(x => fundingSourcesIDs.Contains(x.FundingSourceID));

                if (!projectFundingSourceExpenditures.Any())
                {
                    if (string.IsNullOrWhiteSpace(projectUpdateBatch.ExpendituresNote))
                    {
                        errors.Add(FirmaValidationMessages.ExplanationNecessaryForProjectExemptYears);
                    }
                }
                else
                {
                    if (!fundingSources.Any())
                    {
                        var yearsForErrorDisplay = string.Join(", ", FirmaHelpers.CalculateYearRanges(yearsExpected));
                        errors.Add($"Missing Expenditures for {string.Join(", ", yearsForErrorDisplay)}");
                    }
                    else
                    {
                        var missingFundingSourceYears =
                            new Dictionary <ProjectFirmaModels.Models.FundingSource, IEnumerable <int> >();
                        foreach (var fundingSource in fundingSources)
                        {
                            var currentFundingSource = fundingSource;
                            var missingYears         =
                                yearsExpected
                                .GetMissingYears(projectFundingSourceExpenditures
                                                 .Where(x => x.FundingSourceID == currentFundingSource.FundingSourceID)
                                                 .Select(x => x.CalendarYear)).ToList();

                            if (missingYears.Any())
                            {
                                missingFundingSourceYears.Add(currentFundingSource, missingYears);
                            }
                        }

                        foreach (var fundingSource in missingFundingSourceYears)
                        {
                            var yearsForErrorDisplay =
                                string.Join(", ", FirmaHelpers.CalculateYearRanges(fundingSource.Value));
                            errors.Add(
                                $"Missing Expenditures for {FieldDefinitionEnum.FundingSource.ToType().GetFieldDefinitionLabel()} '{fundingSource.Key.GetDisplayName()}' for the following years: {string.Join(", ", yearsForErrorDisplay)}");
                        }
                    }
                }

                return(errors);
            }
            return(new List <string>());
        }
Пример #6
0
        public static List <PerformanceMeasuresValidationResult> ValidatePerformanceMeasures(this ProjectUpdateBatch projectUpdateBatch)
        {
            if (!projectUpdateBatch.AreProjectBasicsValid())
            {
                return(new List <PerformanceMeasuresValidationResult> {
                    new PerformanceMeasuresValidationResult(FirmaValidationMessages.UpdateSectionIsDependentUponBasicsSection)
                });
            }

            List <PerformanceMeasuresValidationResult> results = new List <PerformanceMeasuresValidationResult>();

            var performanceMeasureActualUpdates = projectUpdateBatch.PerformanceMeasureActualUpdates ?? new List <PerformanceMeasureActualUpdate>();

            // What years are expected for this Project?
            var exemptYears   = projectUpdateBatch.GetPerformanceMeasuresExemptReportingYears().Select(x => x.CalendarYear).ToList();
            var yearsExpected = projectUpdateBatch.ProjectUpdate.GetProjectUpdateImplementationStartToCompletionYearRange().Where(x => !exemptYears.Contains(x)).ToList();

            // validation 1: ensure that at least one PM has values for each year that isn't marked as 'No accomplishments to report' from ProjectUpdate Project Implementation start year to min(endyear, currentyear)
            // if the ProjectUpdate record has a stage of Planning/Design, we do not do this validation
            var missingYears = new HashSet <int>();

            if (projectUpdateBatch.ProjectUpdate.ProjectStage.RequiresPerformanceMeasureActuals() || projectUpdateBatch.ProjectUpdate.ProjectStage == ProjectStage.Completed || projectUpdateBatch.ProjectUpdate.ProjectStage == ProjectStage.PostImplementation)
            {
                var yearsEntered = projectUpdateBatch.PerformanceMeasureActualUpdates.Select(x => x.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodCalendarYear).Distinct();
                missingYears = yearsExpected.GetMissingYears(yearsEntered);
            }
            if (missingYears.Any() && !performanceMeasureActualUpdates.Any())
            {
                // There are missing years, but no PMs entered
                results.Add(new PerformanceMeasuresValidationResult(FirmaValidationMessages.PerformanceMeasureOrExemptYearsRequired));
            }

            // What distinct PerformanceMeasures are being worked with?
            var pmausGrouped = performanceMeasureActualUpdates.GroupBy(pmas => pmas.PerformanceMeasureID);

            // Examine each PerformanceMeasure group as a unit to check for problems within the group
            foreach (var performanceMeasureActualUpdateGroup in pmausGrouped)
            {
                var currentPerformanceMeasureActualUpdate = performanceMeasureActualUpdateGroup.First();
                var currentPerformanceMeasureID           = currentPerformanceMeasureActualUpdate.PerformanceMeasureID;

                // validation 2: incomplete PM row (missing performanceMeasureSubcategory option id)
                var performanceMeasureActualsWithIncompleteWarnings = projectUpdateBatch.ValidateNoIncompletePerformanceMeasureActualUpdateRow(currentPerformanceMeasureID);

                // validation 3: duplicate PM row
                var performanceMeasureActualsWithDuplicateWarnings = projectUpdateBatch.ValidateNoDuplicatePerformanceMeasureActualUpdateRow(currentPerformanceMeasureID);

                // validation 4: data entered for exempt years
                var performanceMeasureActualsWithExemptYear = projectUpdateBatch.ValidateNoExemptYearsWithReportedPerformanceMeasureRow(currentPerformanceMeasureID);

                string currentPerformanceMeasureDisplayName = currentPerformanceMeasureActualUpdate.PerformanceMeasure.PerformanceMeasureDisplayName;

                var performanceMeasuresValidationResult = new PerformanceMeasuresValidationResult(
                    currentPerformanceMeasureID,
                    currentPerformanceMeasureDisplayName,
                    missingYears,
                    performanceMeasureActualsWithIncompleteWarnings,
                    performanceMeasureActualsWithDuplicateWarnings,
                    performanceMeasureActualsWithExemptYear);

                results.Add(performanceMeasuresValidationResult);
            }

            return(results);
        }