예제 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors    = new List <ValidationResult>();
            var emptyRows = ProjectGrantAllocationExpenditures?.Where(x =>
                                                                      x.CalendarYearExpenditures.All(y => !y.MonetaryAmount.HasValue));

            if (emptyRows?.Any() ?? false)
            {
                errors.Add(new ValidationResult($"The {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Update could not be saved because there are blank rows. Enter a value in all fields or delete grant allocations for which there is no expenditure data to report."));
            }

            return(errors);
        }
예제 #2
0
 public IEnumerable <Organization> GetOrganizationsToReportInAccomplishments()
 {
     if (MultiTenantHelpers.GetRelationshipTypeToReportInAccomplishmentsDashboard() == null)
     {
         // Default is Funding Organizations
         var organizations = ProjectGrantAllocationExpenditures.Select(x => x.GrantAllocation.BottommostOrganization)
                             .Union(ProjectGrantAllocationRequests
                                    .Select(x => x.GrantAllocation.BottommostOrganization))
                             .Distinct(new HavePrimaryKeyComparer <Organization>());
         return(organizations);
     }
     else
     {
         return(ProjectOrganizations.Where(x => x.RelationshipType.ReportInAccomplishmentsDashboard)
                .Select(x => x.Organization).ToList());
     }
 }
        public void UpdateModel(Models.Project project,
                                List <Models.ProjectGrantAllocationExpenditure> currentProjectGrantAllocationExpenditures,
                                IList <Models.ProjectGrantAllocationExpenditure> allProjectGrantAllocationExpenditures)
        {
            var projectGrantAllocationExpendituresUpdated = new List <Models.ProjectGrantAllocationExpenditure>();

            if (ProjectGrantAllocationExpenditures != null)
            {
                // Completely rebuild the list
                projectGrantAllocationExpendituresUpdated = ProjectGrantAllocationExpenditures.SelectMany(x => x.ToProjectGrantAllocationExpenditures()).ToList();
            }


            var currentProjectExemptYears = project.GetExpendituresExemptReportingYears();

            HttpRequestStorage.DatabaseEntities.ProjectExemptReportingYears.Load();
            var allProjectExemptYears       = HttpRequestStorage.DatabaseEntities.ProjectExemptReportingYears.Local;
            var projectExemptReportingYears = new List <ProjectExemptReportingYear>();

            if (ProjectExemptReportingYears != null)
            {
                // Completely rebuild the list
                projectExemptReportingYears =
                    ProjectExemptReportingYears.Where(x => x.IsExempt)
                    .Select(x => new ProjectExemptReportingYear(x.ProjectExemptReportingYearID, x.ProjectID, x.CalendarYear, ProjectExemptReportingType.Expenditures.ProjectExemptReportingTypeID))
                    .ToList();
            }
            currentProjectExemptYears.Merge(projectExemptReportingYears,
                                            allProjectExemptYears,
                                            (x, y) => x.ProjectID == y.ProjectID && x.CalendarYear == y.CalendarYear && x.ProjectExemptReportingTypeID == y.ProjectExemptReportingTypeID);

            project.NoExpendituresToReportExplanation = Explanation;

            currentProjectGrantAllocationExpenditures.Merge(projectGrantAllocationExpendituresUpdated,
                                                            allProjectGrantAllocationExpenditures,
                                                            (x, y) => x.ProjectID == y.ProjectID && x.GrantAllocationID == y.GrantAllocationID && x.CalendarYear == y.CalendarYear,
                                                            (x, y) => x.ExpenditureAmount = y.ExpenditureAmount);
        }
        /// <summary>
        /// Dependent type names of this entity
        /// </summary>
        public void DeleteChildren(DatabaseEntities dbContext)
        {
            foreach (var x in GrantAllocationAwardLandownerCostShareLineItems.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in InteractionEventProjects.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in NotificationProjects.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in PerformanceMeasureActuals.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in PerformanceMeasureExpecteds.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectClassifications.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectCustomAttributes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectDocuments.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectExemptReportingYears.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectExternalLinks.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectFundingSources.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationExpenditures.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationRequests.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectImages.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectInternalNotes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectLocations.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectLocationStagings.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectNotes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectOrganizations.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectPeople.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectPriorityLandscapes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectPrograms.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectRegions.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectTags.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectUpdateBatches.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in Treatments.ToList())
            {
                x.DeleteFull(dbContext);
            }
        }
        /// <summary>
        /// Active Dependent type names of this object
        /// </summary>
        public List <string> DependentObjectNames()
        {
            var dependentObjects = new List <string>();

            if (GrantAllocationAwardLandownerCostShareLineItems.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationAwardLandownerCostShareLineItem).Name);
            }

            if (InteractionEventProjects.Any())
            {
                dependentObjects.Add(typeof(InteractionEventProject).Name);
            }

            if (NotificationProjects.Any())
            {
                dependentObjects.Add(typeof(NotificationProject).Name);
            }

            if (PerformanceMeasureActuals.Any())
            {
                dependentObjects.Add(typeof(PerformanceMeasureActual).Name);
            }

            if (PerformanceMeasureExpecteds.Any())
            {
                dependentObjects.Add(typeof(PerformanceMeasureExpected).Name);
            }

            if (ProjectClassifications.Any())
            {
                dependentObjects.Add(typeof(ProjectClassification).Name);
            }

            if (ProjectCustomAttributes.Any())
            {
                dependentObjects.Add(typeof(ProjectCustomAttribute).Name);
            }

            if (ProjectDocuments.Any())
            {
                dependentObjects.Add(typeof(ProjectDocument).Name);
            }

            if (ProjectExemptReportingYears.Any())
            {
                dependentObjects.Add(typeof(ProjectExemptReportingYear).Name);
            }

            if (ProjectExternalLinks.Any())
            {
                dependentObjects.Add(typeof(ProjectExternalLink).Name);
            }

            if (ProjectFundingSources.Any())
            {
                dependentObjects.Add(typeof(ProjectFundingSource).Name);
            }

            if (ProjectGrantAllocationExpenditures.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationExpenditure).Name);
            }

            if (ProjectGrantAllocationRequests.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationRequest).Name);
            }

            if (ProjectImages.Any())
            {
                dependentObjects.Add(typeof(ProjectImage).Name);
            }

            if (ProjectInternalNotes.Any())
            {
                dependentObjects.Add(typeof(ProjectInternalNote).Name);
            }

            if (ProjectLocations.Any())
            {
                dependentObjects.Add(typeof(ProjectLocation).Name);
            }

            if (ProjectLocationStagings.Any())
            {
                dependentObjects.Add(typeof(ProjectLocationStaging).Name);
            }

            if (ProjectNotes.Any())
            {
                dependentObjects.Add(typeof(ProjectNote).Name);
            }

            if (ProjectOrganizations.Any())
            {
                dependentObjects.Add(typeof(ProjectOrganization).Name);
            }

            if (ProjectPeople.Any())
            {
                dependentObjects.Add(typeof(ProjectPerson).Name);
            }

            if (ProjectPriorityLandscapes.Any())
            {
                dependentObjects.Add(typeof(ProjectPriorityLandscape).Name);
            }

            if (ProjectPrograms.Any())
            {
                dependentObjects.Add(typeof(ProjectProgram).Name);
            }

            if (ProjectRegions.Any())
            {
                dependentObjects.Add(typeof(ProjectRegion).Name);
            }

            if (ProjectTags.Any())
            {
                dependentObjects.Add(typeof(ProjectTag).Name);
            }

            if (ProjectUpdateBatches.Any())
            {
                dependentObjects.Add(typeof(ProjectUpdateBatch).Name);
            }

            if (Treatments.Any())
            {
                dependentObjects.Add(typeof(Treatment).Name);
            }
            return(dependentObjects.Distinct().ToList());
        }
 /// <summary>
 /// Does this object have any dependent objects? (If it does have dependent objects, these would need to be deleted before this object could be deleted.)
 /// </summary>
 /// <returns></returns>
 public bool HasDependentObjects()
 {
     return(GrantAllocationAwardLandownerCostShareLineItems.Any() || InteractionEventProjects.Any() || NotificationProjects.Any() || PerformanceMeasureActuals.Any() || PerformanceMeasureExpecteds.Any() || ProjectClassifications.Any() || ProjectCustomAttributes.Any() || ProjectDocuments.Any() || ProjectExemptReportingYears.Any() || ProjectExternalLinks.Any() || ProjectFundingSources.Any() || ProjectGrantAllocationExpenditures.Any() || ProjectGrantAllocationRequests.Any() || ProjectImages.Any() || ProjectInternalNotes.Any() || ProjectLocations.Any() || ProjectLocationStagings.Any() || ProjectNotes.Any() || ProjectOrganizations.Any() || ProjectPeople.Any() || ProjectPriorityLandscapes.Any() || ProjectPrograms.Any() || ProjectRegions.Any() || ProjectTags.Any() || ProjectUpdateBatches.Any() || Treatments.Any());
 }
 /// <summary>
 /// Does this object have any dependent objects? (If it does have dependent objects, these would need to be deleted before this object could be deleted.)
 /// </summary>
 /// <returns></returns>
 public bool HasDependentObjects()
 {
     return(AgreementGrantAllocations.Any() || GrantAllocationAwards.Any() || GrantAllocationBudgetLineItems.Any() || GrantAllocationChangeLogs.Any() || GrantAllocationExpenditures.Any() || GrantAllocationFileResources.Any() || GrantAllocationNotes.Any() || GrantAllocationNoteInternals.Any() || GrantAllocationProgramIndexProjectCodes.Any() || GrantAllocationProgramManagers.Any() || InvoiceLineItems.Any() || ProjectGrantAllocationExpenditures.Any() || ProjectGrantAllocationExpenditureUpdates.Any() || ProjectGrantAllocationRequests.Any() || ProjectGrantAllocationRequestUpdates.Any());
 }
        /// <summary>
        /// Dependent type names of this entity
        /// </summary>
        public void DeleteChildren(DatabaseEntities dbContext)
        {
            foreach (var x in AgreementGrantAllocations.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationAwards.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationBudgetLineItems.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationChangeLogs.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationExpenditures.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationFileResources.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationNotes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationNoteInternals.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationProgramIndexProjectCodes.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in GrantAllocationProgramManagers.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in InvoiceLineItems.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationExpenditures.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationExpenditureUpdates.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationRequests.ToList())
            {
                x.DeleteFull(dbContext);
            }

            foreach (var x in ProjectGrantAllocationRequestUpdates.ToList())
            {
                x.DeleteFull(dbContext);
            }
        }
        /// <summary>
        /// Active Dependent type names of this object
        /// </summary>
        public List <string> DependentObjectNames()
        {
            var dependentObjects = new List <string>();

            if (AgreementGrantAllocations.Any())
            {
                dependentObjects.Add(typeof(AgreementGrantAllocation).Name);
            }

            if (GrantAllocationAwards.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationAward).Name);
            }

            if (GrantAllocationBudgetLineItems.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationBudgetLineItem).Name);
            }

            if (GrantAllocationChangeLogs.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationChangeLog).Name);
            }

            if (GrantAllocationExpenditures.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationExpenditure).Name);
            }

            if (GrantAllocationFileResources.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationFileResource).Name);
            }

            if (GrantAllocationNotes.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationNote).Name);
            }

            if (GrantAllocationNoteInternals.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationNoteInternal).Name);
            }

            if (GrantAllocationProgramIndexProjectCodes.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationProgramIndexProjectCode).Name);
            }

            if (GrantAllocationProgramManagers.Any())
            {
                dependentObjects.Add(typeof(GrantAllocationProgramManager).Name);
            }

            if (InvoiceLineItems.Any())
            {
                dependentObjects.Add(typeof(InvoiceLineItem).Name);
            }

            if (ProjectGrantAllocationExpenditures.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationExpenditure).Name);
            }

            if (ProjectGrantAllocationExpenditureUpdates.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationExpenditureUpdate).Name);
            }

            if (ProjectGrantAllocationRequests.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationRequest).Name);
            }

            if (ProjectGrantAllocationRequestUpdates.Any())
            {
                dependentObjects.Add(typeof(ProjectGrantAllocationRequestUpdate).Name);
            }
            return(dependentObjects.Distinct().ToList());
        }