public void UpdateModel(List <Models.ProjectGrantAllocationRequest> currentProjectGrantAllocationRequests,
                                IList <Models.ProjectGrantAllocationRequest> allProjectGrantAllocationRequests,
                                Models.Project project,
                                List <ProjectFundingSource> currentProjectFundingSources,
                                IList <ProjectFundingSource> allProjectFundingSources)
        {
            var projectGrantAllocationRequestsModified = new List <Models.ProjectGrantAllocationRequest>();

            if (ProjectGrantAllocationRequests != null)
            {
                // Completely rebuild the list
                projectGrantAllocationRequestsModified = ProjectGrantAllocationRequests.Select(x => x.ToProjectGrantAllocationRequest()).ToList();
            }

            if (ForProject) // never null
            {
                if (project == null)
                {
                    throw new InvalidOperationException(
                              $"Project is required to update {Models.FieldDefinition.GrantAllocation.GetFieldDefinitionLabel()} Requests for a Project");
                }

                //Update the ProjectFundingSources
                var projectFundingSourcesUpdated = new List <Models.ProjectFundingSource>();
                if (FundingSourceIDs != null && FundingSourceIDs.Any())
                {
                    // Completely rebuild the list
                    projectFundingSourcesUpdated = FundingSourceIDs.Select(x => new ProjectFundingSource(project.ProjectID, x)).ToList();
                }

                currentProjectFundingSources.Merge(projectFundingSourcesUpdated,
                                                   allProjectFundingSources,
                                                   (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID);

                //Update Project fields
                project.ProjectFundingSourceNotes = ProjectFundingSourceNotes;
                project.EstimatedTotalCost        = ProjectEstimatedTotalCost;
            }

            currentProjectGrantAllocationRequests.Merge(projectGrantAllocationRequestsModified,
                                                        allProjectGrantAllocationRequests,
                                                        (x, y) => x.ProjectID == y.ProjectID && x.GrantAllocationID == y.GrantAllocationID,
                                                        (x, y) =>
            {
                x.TotalAmount = y.TotalAmount;
            });
        }
        public void UpdateModel(Models.Project project,
                                List <Models.ProjectGrantAllocationRequest> currentProjectGrantAllocationRequests,
                                IList <Models.ProjectGrantAllocationRequest> allProjectGrantAllocationRequests,
                                List <ProjectFundingSource> currentProjectFundingSources,
                                IList <ProjectFundingSource> allProjectFundingSources)
        {
            //Update the ProjectGrantAllocationRequests
            var projectGrantAllocationRequestsUpdated = new List <Models.ProjectGrantAllocationRequest>();

            if (ProjectGrantAllocationRequestSimples != null)
            {
                // Completely rebuild the list
                projectGrantAllocationRequestsUpdated = ProjectGrantAllocationRequestSimples
                                                        .Select(x => x.ToProjectGrantAllocationRequest()).ToList();
            }

            currentProjectGrantAllocationRequests.Merge(projectGrantAllocationRequestsUpdated,
                                                        allProjectGrantAllocationRequests,
                                                        (x, y) => x.ProjectID == y.ProjectID && x.GrantAllocationID == y.GrantAllocationID,
                                                        (x, y) => { x.TotalAmount = y.TotalAmount; });

            //Update the ProjectFundingSources
            var projectFundingSourcesUpdated = new List <Models.ProjectFundingSource>();

            if (FundingSourceIDs != null && FundingSourceIDs.Any())
            {
                // Completely rebuild the list
                projectFundingSourcesUpdated = FundingSourceIDs.Select(x => new ProjectFundingSource(project.ProjectID, x)).ToList();
            }

            currentProjectFundingSources.Merge(projectFundingSourcesUpdated,
                                               allProjectFundingSources,
                                               (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID);

            //Update Project fields
            project.ProjectFundingSourceNotes = ProjectFundingSourceNotes;
            project.EstimatedTotalCost        = ProjectEstimatedTotalCost;
        }
        public void UpdateModel(ProjectUpdateBatch projectUpdateBatch,
                                List <ProjectGrantAllocationRequestUpdate> currentProjectGrantAllocationRequestUpdates,
                                IList <ProjectGrantAllocationRequestUpdate> allProjectGrantAllocationRequestUpdates,
                                Models.ProjectUpdate projectUpdate,
                                List <ProjectFundingSourceUpdate> currentProjectFundingSourceUpdates,
                                IList <ProjectFundingSourceUpdate> allProjectFundingSourceUpdates)
        {
            var dateNow = DateTime.Now;
            var projectGrantAllocationRequestUpdatesUpdated = new List <ProjectGrantAllocationRequestUpdate>();

            if (ProjectGrantAllocationRequests != null)
            {
                foreach (var projectGrantAllocationRequestSimple in ProjectGrantAllocationRequests)
                {
                    var existingCurrentOne = currentProjectGrantAllocationRequestUpdates.SingleOrDefault(x =>
                                                                                                         x.ProjectUpdateBatchID == projectGrantAllocationRequestSimple.ProjectID &&
                                                                                                         x.GrantAllocationID == projectGrantAllocationRequestSimple.GrantAllocationID);
                    if (existingCurrentOne != null)
                    {
                        var projectGrantAllocationRequestToAdd =
                            projectGrantAllocationRequestSimple.ToProjectGrantAllocationRequestUpdate(
                                existingCurrentOne.CreateDate, dateNow, existingCurrentOne.ImportedFromTabularData);
                        projectGrantAllocationRequestUpdatesUpdated.Add(projectGrantAllocationRequestToAdd);
                    }
                    else
                    {
                        var projectGrantAllocationRequestToAdd =
                            projectGrantAllocationRequestSimple.ToProjectGrantAllocationRequestUpdate(
                                dateNow, null, false);
                        projectGrantAllocationRequestUpdatesUpdated.Add(projectGrantAllocationRequestToAdd);
                    }
                }
            }

            currentProjectGrantAllocationRequestUpdates.Merge(projectGrantAllocationRequestUpdatesUpdated,
                                                              allProjectGrantAllocationRequestUpdates,
                                                              (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.GrantAllocationID == y.GrantAllocationID,
                                                              (x, y) =>
            {
                x.TotalAmount             = y.TotalAmount;
                x.MatchAmount             = y.MatchAmount;
                x.PayAmount               = y.PayAmount;
                x.UpdateDate              = y.UpdateDate;
                x.CreateDate              = y.CreateDate;
                x.ImportedFromTabularData = y.ImportedFromTabularData;
            });

            //Update the ProjectFundingSourceUpdates
            var projectFundingSourceUpdatesUpdated = new List <Models.ProjectFundingSourceUpdate>();

            if (FundingSourceIDs != null && FundingSourceIDs.Any())
            {
                // Completely rebuild the list
                projectFundingSourceUpdatesUpdated = FundingSourceIDs.Select(x => new ProjectFundingSourceUpdate(projectUpdateBatch.ProjectUpdateBatchID, x)).ToList();
            }

            currentProjectFundingSourceUpdates.Merge(projectFundingSourceUpdatesUpdated,
                                                     allProjectFundingSourceUpdates,
                                                     (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.FundingSourceID == y.FundingSourceID);

            //Update Project Update fields
            projectUpdate.ProjectFundingSourceNotes = ProjectFundingSourceNotes;
            projectUpdate.EstimatedTotalCost        = ProjectEstimatedTotalCost;
        }
Пример #4
0
        public void UpdateModel(List <Models.ProjectGrantAllocationRequest> currentProjectGrantAllocationRequests,
                                IList <Models.ProjectGrantAllocationRequest> allProjectGrantAllocationRequests,
                                Models.Project project,
                                List <ProjectFundingSource> currentProjectFundingSources,
                                IList <ProjectFundingSource> allProjectFundingSources)
        {
            var dateNow = DateTime.Now;
            var projectGrantAllocationRequestsModified = new List <Models.ProjectGrantAllocationRequest>();

            if (ProjectGrantAllocationRequests != null)
            {
                foreach (var projectGrantAllocationRequestSimple in ProjectGrantAllocationRequests)
                {
                    var existingCurrentOne = currentProjectGrantAllocationRequests.SingleOrDefault(x =>
                                                                                                   x.ProjectID == projectGrantAllocationRequestSimple.ProjectID &&
                                                                                                   x.GrantAllocationID == projectGrantAllocationRequestSimple.GrantAllocationID);
                    if (existingCurrentOne != null)
                    {
                        var projectGrantAllocationRequestToAdd =
                            projectGrantAllocationRequestSimple.ToProjectGrantAllocationRequest(
                                existingCurrentOne.CreateDate, dateNow, existingCurrentOne.ImportedFromTabularData);
                        projectGrantAllocationRequestsModified.Add(projectGrantAllocationRequestToAdd);
                    }
                    else
                    {
                        var projectGrantAllocationRequestToAdd =
                            projectGrantAllocationRequestSimple.ToProjectGrantAllocationRequest(
                                dateNow, null, false);
                        projectGrantAllocationRequestsModified.Add(projectGrantAllocationRequestToAdd);
                    }
                }
            }

            if (ForProject) // never null
            {
                if (project == null)
                {
                    throw new InvalidOperationException(
                              $"Project is required to update {Models.FieldDefinition.GrantAllocation.GetFieldDefinitionLabel()} Requests for a Project");
                }

                //Update the ProjectFundingSources
                var projectFundingSourcesUpdated = new List <Models.ProjectFundingSource>();
                if (FundingSourceIDs != null && FundingSourceIDs.Any())
                {
                    // Completely rebuild the list
                    projectFundingSourcesUpdated = FundingSourceIDs.Select(x => new ProjectFundingSource(project.ProjectID, x)).ToList();
                }

                currentProjectFundingSources.Merge(projectFundingSourcesUpdated,
                                                   allProjectFundingSources,
                                                   (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID);

                //Update Project fields
                project.ProjectFundingSourceNotes = ProjectFundingSourceNotes;
                project.EstimatedTotalCost        = ProjectEstimatedTotalCost;
            }

            currentProjectGrantAllocationRequests.Merge(projectGrantAllocationRequestsModified,
                                                        allProjectGrantAllocationRequests,
                                                        (x, y) => x.ProjectID == y.ProjectID && x.GrantAllocationID == y.GrantAllocationID,
                                                        (x, y) =>
            {
                x.TotalAmount             = y.TotalAmount;
                x.MatchAmount             = y.MatchAmount;
                x.PayAmount               = y.PayAmount;
                x.UpdateDate              = y.UpdateDate;
                x.CreateDate              = y.CreateDate;
                x.ImportedFromTabularData = y.ImportedFromTabularData;
            });
        }