예제 #1
0
        public static void CommitChangesToProject(ProjectUpdateBatch projectUpdateBatch, DatabaseEntities databaseEntities)
        {
            var project = projectUpdateBatch.Project;
            var currentPerformanceMeasureActuals = project.PerformanceMeasureActuals.ToList();

            currentPerformanceMeasureActuals.ForEach(pmav => pmav.DeleteFull(databaseEntities));
            currentPerformanceMeasureActuals.Clear();

            if (projectUpdateBatch.AreAccomplishmentsRelevant() && projectUpdateBatch.PerformanceMeasureActualUpdates.Any())
            {
                // Completely rebuild the list
                projectUpdateBatch.PerformanceMeasureActualUpdates.ToList().ForEach(x =>
                {
                    var performanceMeasureActual = new PerformanceMeasureActual(project, x.PerformanceMeasure, x.ActualValue ?? 0, x.PerformanceMeasureReportingPeriod);
                    databaseEntities.AllPerformanceMeasureActuals.Add(performanceMeasureActual);
                    var performanceMeasureActualSubcategoryOptionUpdates = x.PerformanceMeasureActualSubcategoryOptionUpdates.ToList();
                    if (performanceMeasureActualSubcategoryOptionUpdates.Any())
                    {
                        performanceMeasureActualSubcategoryOptionUpdates.ForEach(
                            y =>
                            databaseEntities.AllPerformanceMeasureActualSubcategoryOptions.Add(new PerformanceMeasureActualSubcategoryOption(performanceMeasureActual,
                                                                                                                                             y.PerformanceMeasureSubcategoryOption,
                                                                                                                                             y.PerformanceMeasure,
                                                                                                                                             y.PerformanceMeasureSubcategory)));
                    }
                });
            }
        }
        public static void CommitChangesToProject(ProjectUpdateBatch projectUpdateBatch, DatabaseEntities databaseEntities)
        {
            var project = projectUpdateBatch.Project;
            var currentPerformanceMeasureExpecteds = project.PerformanceMeasureExpecteds.ToList();

            currentPerformanceMeasureExpecteds.ForEach(pmav => pmav.DeleteFull(databaseEntities));
            currentPerformanceMeasureExpecteds.Clear();

            if (projectUpdateBatch.AreAccomplishmentsRelevant() && projectUpdateBatch.PerformanceMeasureExpectedUpdates.Any())
            {
                // Completely rebuild the list
                projectUpdateBatch.PerformanceMeasureExpectedUpdates.ToList().ForEach(x =>
                {
                    var performanceMeasureExpected = new PerformanceMeasureExpected(project, x.PerformanceMeasure)
                    {
                        ExpectedValue = x.ExpectedValue
                    };
                    databaseEntities.AllPerformanceMeasureExpecteds.Add(performanceMeasureExpected);
                    var performanceMeasureExpectedSubcategoryOptionUpdates = x.PerformanceMeasureExpectedSubcategoryOptionUpdates.ToList();
                    if (performanceMeasureExpectedSubcategoryOptionUpdates.Any())
                    {
                        performanceMeasureExpectedSubcategoryOptionUpdates.ForEach(
                            y =>
                            databaseEntities.AllPerformanceMeasureExpectedSubcategoryOptions.Add(new PerformanceMeasureExpectedSubcategoryOption(performanceMeasureExpected,
                                                                                                                                                 y.PerformanceMeasureSubcategoryOption,
                                                                                                                                                 y.PerformanceMeasure,
                                                                                                                                                 y.PerformanceMeasureSubcategory)));
                    }
                });
            }
        }
        public static void CommitChangesToProject(ProjectUpdateBatch projectUpdateBatch,
                                                  IList <PerformanceMeasureActual> allPerformanceMeasureActuals,
                                                  IList <PerformanceMeasureActualSubcategoryOption> allPerformanceMeasureActualSubcategoryOptions)
        {
            var project = projectUpdateBatch.Project;
            var currentPerformanceMeasureActuals = project.PerformanceMeasureActuals.ToList();

            currentPerformanceMeasureActuals.ForEach(pmav =>
            {
                pmav.PerformanceMeasureActualSubcategoryOptions.ToList().ForEach(pmavso => allPerformanceMeasureActualSubcategoryOptions.Remove(pmavso));
                allPerformanceMeasureActuals.Remove(pmav);
            });
            currentPerformanceMeasureActuals.Clear();

            if (projectUpdateBatch.AreAccomplishmentsRelevant() && projectUpdateBatch.PerformanceMeasureActualUpdates.Any())
            {
                // Completely rebuild the list
                projectUpdateBatch.PerformanceMeasureActualUpdates.ToList().ForEach(x =>
                {
                    var performanceMeasureActual = new PerformanceMeasureActual(project, x.PerformanceMeasure, x.CalendarYear, x.ActualValue ?? 0);
                    allPerformanceMeasureActuals.Add(performanceMeasureActual);
                    var performanceMeasureActualSubcategoryOptionUpdates = x.PerformanceMeasureActualSubcategoryOptionUpdates.ToList();
                    if (performanceMeasureActualSubcategoryOptionUpdates.Any())
                    {
                        performanceMeasureActualSubcategoryOptionUpdates.ForEach(
                            y =>
                            allPerformanceMeasureActualSubcategoryOptions.Add(new PerformanceMeasureActualSubcategoryOption(performanceMeasureActual,
                                                                                                                            y.PerformanceMeasureSubcategoryOption,
                                                                                                                            y.PerformanceMeasure,
                                                                                                                            y.PerformanceMeasureSubcategory)));
                    }
                });
            }
        }
        public static void CreateFromProject(ProjectUpdateBatch projectUpdateBatch)
        {
            if (projectUpdateBatch.AreAccomplishmentsRelevant())
            {
                var project = projectUpdateBatch.Project;
                var performanceMeasureActualUpdates  = new List <PerformanceMeasureActualUpdate>();
                var currentPerformanceMeasureActuals = project.PerformanceMeasureActuals.ToList();
                var currentYear    = FirmaDateUtilities.CalculateCurrentYearToUseForUpToAllowableInputInReporting();
                var completionYear = projectUpdateBatch.ProjectUpdate != null
                    ? projectUpdateBatch.ProjectUpdate.GetCompletionYear()
                    : project.GetCompletionYear();

                var currentStage = projectUpdateBatch.ProjectUpdate != null
                    ? projectUpdateBatch.ProjectUpdate.ProjectStage
                    : project.ProjectStage;
                var endYearToFill = Math.Min(completionYear ?? currentYear, currentYear);
                // if we have a project completion year, we only fill up to that unless current year is earlier; no completion year set we use current year
                if (currentPerformanceMeasureActuals.Any())
                {
                    performanceMeasureActualUpdates.AddRange(
                        currentPerformanceMeasureActuals.Select(
                            performanceMeasureActual =>
                            ClonePerformanceMeasureValue(projectUpdateBatch, performanceMeasureActual,
                                                         performanceMeasureActual.CalendarYear, performanceMeasureActual.ActualValue)));
                }
                // use expected values if any only if we are not in Planning/Design
                else if (currentStage != ProjectStage.Planned)
                {
                    var currentPerformanceMeasureExpecteds =
                        new List <IPerformanceMeasureValue>(project.PerformanceMeasureExpecteds.ToList());
                    if (currentPerformanceMeasureExpecteds.Any())
                    {
                        // we want to pre-create records from project Start Year to current year; if no start year then we just create for current year
                        var initialYearToFill = project.GetImplementationStartYear() ?? currentYear;
                        performanceMeasureActualUpdates.AddRange(
                            CreatePerformanceMeasureActualUpdateRecordsForGivenYearToCurrentYear(projectUpdateBatch,
                                                                                                 currentPerformanceMeasureExpecteds,
                                                                                                 initialYearToFill,
                                                                                                 endYearToFill));
                    }
                }
                projectUpdateBatch.PerformanceMeasureActualUpdates = performanceMeasureActualUpdates;
            }
        }
예제 #5
0
        public static List <ProjectSectionSimple> GetProjectUpdateSections(this ProjectWorkflowSectionGrouping projectWorkflowSectionGrouping,
                                                                           FirmaSession currentFirmaSession,
                                                                           ProjectUpdateBatch projectUpdateBatch,
                                                                           ProjectUpdateStatus projectUpdateStatus,
                                                                           bool ignoreStatus,
                                                                           bool hasEditableCustomAttributes)
        {
            switch (projectWorkflowSectionGrouping.ToEnum)
            {
            case ProjectWorkflowSectionGroupingEnum.Overview:
                // remove the custom attributes section from the overview section to begin with
                var projectUpdateSectionForCustomAttributes = projectWorkflowSectionGrouping.ProjectUpdateSections.Except(new List <ProjectUpdateSection> {
                    ProjectUpdateSection.CustomAttributes
                }).ToList();
                // If there are custom attribute types for this tenant, we can add the section back
                if (hasEditableCustomAttributes)
                {
                    projectUpdateSectionForCustomAttributes.Add(ProjectUpdateSection.CustomAttributes);
                }
                return(GetProjectUpdateSectionsImpl(projectUpdateBatch, projectUpdateSectionForCustomAttributes, projectUpdateStatus, ignoreStatus));

            case ProjectWorkflowSectionGroupingEnum.SpatialInformation:
                var geospatialAreaTypes = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes;
                var updateSections      = projectWorkflowSectionGrouping.ProjectUpdateSections.Except(new List <ProjectUpdateSection> {
                    ProjectUpdateSection.BulkSetSpatialInformation
                }).ToList();
                if (geospatialAreaTypes.Count() > 1)
                {
                    updateSections.Add(ProjectUpdateSection.BulkSetSpatialInformation);
                }
                var projectUpdateSections = GetProjectUpdateSectionsImpl(projectUpdateBatch, updateSections, projectUpdateStatus, ignoreStatus);
                //Bulk Set is the only section setup for spatial areas in the DB. so we always want to start with that sort order
                int maxSortOrder = ProjectUpdateSection.BulkSetSpatialInformation.SortOrder;
                projectUpdateSections.AddRange(geospatialAreaTypes
                                               .OrderBy(x => x.GeospatialAreaTypeName).ToList().Select((geospatialAreaType, index) =>
                                                                                                       new ProjectSectionSimple(geospatialAreaType.GeospatialAreaTypeNamePluralized, maxSortOrder + index + 1,
                                                                                                                                !projectUpdateBatch.IsNew(), projectWorkflowSectionGrouping,
                                                                                                                                projectUpdateBatch.IsNew() ? null :
                                                                                                                                SitkaRoute <ProjectUpdateController> .BuildUrlFromExpression(y =>
                                                                                                                                                                                             y.GeospatialArea(projectUpdateBatch.Project, geospatialAreaType)),
                                                                                                                                projectUpdateStatus != null && projectUpdateBatch.IsProjectGeospatialAreaValid(geospatialAreaType),
                                                                                                                                projectUpdateStatus != null && IsGeospatialAreaUpdated(projectUpdateBatch, geospatialAreaType)
                                                                                                                                )));
                return(projectUpdateSections);

            case ProjectWorkflowSectionGroupingEnum.Accomplishments:
                var projectUpdateSectionsForPerformanceMeasures = projectWorkflowSectionGrouping.ProjectUpdateSections.Except(new List <ProjectUpdateSection> {
                    ProjectUpdateSection.ReportedAccomplishments
                }).ToList();
                if (projectUpdateBatch.AreAccomplishmentsRelevant())
                {
                    projectUpdateSectionsForPerformanceMeasures.Add(ProjectUpdateSection.ReportedAccomplishments);
                }
                return(GetProjectUpdateSectionsImpl(projectUpdateBatch, projectUpdateSectionsForPerformanceMeasures, projectUpdateStatus, ignoreStatus));

            case ProjectWorkflowSectionGroupingEnum.Financials:
                var projectUpdateSectionsForExpenditures = projectWorkflowSectionGrouping.ProjectUpdateSections.Except(new List <ProjectUpdateSection> {
                    ProjectUpdateSection.Budget
                }).ToList();
                if (projectUpdateBatch.Project.IsExpectedFundingRelevant())
                {
                    projectUpdateSectionsForExpenditures.Add(ProjectUpdateSection.Budget);
                }
                return(GetProjectUpdateSectionsImpl(projectUpdateBatch, projectUpdateSectionsForExpenditures, projectUpdateStatus, ignoreStatus));

            case ProjectWorkflowSectionGroupingEnum.AdditionalData:
                var additionalDataProjectUpdateSections = projectWorkflowSectionGrouping.ProjectUpdateSections.ToList();

                var sections = GetProjectUpdateSectionsImpl(projectUpdateBatch, additionalDataProjectUpdateSections, projectUpdateStatus, ignoreStatus);
                // Remove Technical Assistance Requests for all tenants except Idaho
                if (!MultiTenantHelpers.UsesTechnicalAssistanceParameters())
                {
                    sections = sections.Where(x => x.SectionDisplayName != ProjectUpdateSection.TechnicalAssistanceRequests.ProjectUpdateSectionDisplayName).ToList();
                }
                return(sections);

            // Partner Finder
            // Whole section is conditional
            case ProjectWorkflowSectionGroupingEnum.Partners:
                bool shouldShowPartnerFinder = new MatchMakerViewPotentialPartnersFeature().HasPermissionForProjectByFirmaSession(currentFirmaSession, projectUpdateBatch.Project);
                if (!shouldShowPartnerFinder)
                {
                    // An empty group won't be shown.
                    return(new List <ProjectSectionSimple>());
                }

                var projectUpdateSectionsForPartners = projectWorkflowSectionGrouping.ProjectUpdateSections.Except(new List <ProjectUpdateSection> {
                    ProjectUpdateSection.Budget
                }).ToList();
                return(GetProjectUpdateSectionsImpl(projectUpdateBatch, projectUpdateSectionsForPartners, projectUpdateStatus, ignoreStatus));

            default:
                throw new ArgumentOutOfRangeException($"Unhandled Workflow Section Grouping: {projectWorkflowSectionGrouping.ToEnum}");
            }
        }