Example #1
0
        public void UpdateModel(ProjectFirmaModels.Models.Project project,
                                List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> currentProjectFundingSourceExpenditures,
                                IList <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> allProjectFundingSourceExpenditures)
        {
            var databaseEntities = HttpRequestStorage.DatabaseEntities;

            databaseEntities.ProjectExemptReportingYearUpdates.Load();
            databaseEntities.ProjectRelevantCostTypes.Load();

            var projectFundingSourceExpendituresUpdated = new List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure>();

            if (ProjectFundingSourceExpenditures != null)
            {
                // Completely rebuild the list
                projectFundingSourceExpendituresUpdated = ProjectFundingSourceExpenditures.Where(x => x.IsRelevant).SelectMany(x => x.ToProjectFundingSourceExpendituresSetNullToZero()).ToList();
            }

            currentProjectFundingSourceExpenditures.Merge(projectFundingSourceExpendituresUpdated,
                                                          allProjectFundingSourceExpenditures,
                                                          (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID && x.CostTypeID == y.CostTypeID && x.CalendarYear == y.CalendarYear,
                                                          (x, y) => x.ExpenditureAmount = y.ExpenditureAmount, databaseEntities);

            var currentProjectRelevantCostTypes = project.GetExpendituresRelevantCostTypes();
            var allProjectRelevantCostTypes     = databaseEntities.AllProjectRelevantCostTypes.Local;
            var projectRelevantCostTypes        = new List <ProjectRelevantCostType>();

            if (ProjectRelevantCostTypes != null)
            {
                // Completely rebuild the list
                projectRelevantCostTypes =
                    ProjectRelevantCostTypes.Where(x => x.IsRelevant)
                    .Select(x => new ProjectRelevantCostType(x.ProjectRelevantCostTypeID, x.ProjectID, x.CostTypeID, ProjectRelevantCostTypeGroup.Expenditures.ProjectRelevantCostTypeGroupID))
                    .ToList();
            }
            currentProjectRelevantCostTypes.Merge(projectRelevantCostTypes,
                                                  allProjectRelevantCostTypes,
                                                  (x, y) => x.ProjectID == y.ProjectID && x.CostTypeID == y.CostTypeID && x.ProjectRelevantCostTypeGroupID == y.ProjectRelevantCostTypeGroupID, databaseEntities);

            project.ExpendituresNote = ProjectFundingSourceExpenditures != null && ProjectFundingSourceExpenditures.Any() ? null : Explanation;
        }
Example #2
0
        public void UpdateModel(ProjectFirmaModels.Models.Project project, DatabaseEntities databaseEntities)
        {
            var currentProjectFundingSourceBudgets = project.ProjectFundingSourceBudgets.ToList();

            databaseEntities.ProjectFundingSourceBudgets.Load();
            var allProjectFundingSourceBudgets           = databaseEntities.AllProjectFundingSourceBudgets.Local;
            var currentProjectNoFundingSourceIdentifieds = project.ProjectNoFundingSourceIdentifieds.ToList();

            databaseEntities.ProjectNoFundingSourceIdentifieds.Load();
            var allProjectNoFundingSourceIdentifieds = HttpRequestStorage.DatabaseEntities.AllProjectNoFundingSourceIdentifieds.Local;

            project.FundingTypeID = FundingTypeID;

            var projectFundingSourceBudgetsUpdated = new List <ProjectFirmaModels.Models.ProjectFundingSourceBudget>();

            if (ProjectFundingSourceBudgets != null)
            {
                // Completely rebuild the list
                projectFundingSourceBudgetsUpdated = ProjectFundingSourceBudgets.Where(x => x.IsRelevant ?? false).SelectMany(x => x.ToProjectFundingSourceBudgets()).ToList();
            }
            currentProjectFundingSourceBudgets.Merge(projectFundingSourceBudgetsUpdated,
                                                     allProjectFundingSourceBudgets,
                                                     (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID && x.CostTypeID == y.CostTypeID && x.CalendarYear == y.CalendarYear,
                                                     (x, y) => x.SetSecuredAndTargetedAmounts(y.SecuredAmount, y.TargetedAmount), databaseEntities);

            var projectNoFundingSourceAmountsUpdated = new List <ProjectNoFundingSourceIdentified>();

            if (FundingTypeID == FundingType.BudgetSameEachYear.FundingTypeID && NoFundingSourceIdentifiedYet != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceAmountsUpdated.Add(new ProjectNoFundingSourceIdentified(project.ProjectID)
                {
                    NoFundingSourceIdentifiedYet = NoFundingSourceIdentifiedYet
                });
            }
            else if (FundingTypeID == FundingType.BudgetVariesByYear.FundingTypeID && NoFundingSourceAmounts != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceAmountsUpdated = NoFundingSourceAmounts.Where(x => x.MonetaryAmount.HasValue)
                                                       .Select(x =>
                                                               new ProjectNoFundingSourceIdentified(project.ProjectID)
                {
                    CalendarYear = x.CalendarYear, NoFundingSourceIdentifiedYet = x.MonetaryAmount.Value
                })
                                                       .ToList();
            }
            // set if funding type is "Varies By Year", delete rows otherwise
            currentProjectNoFundingSourceIdentifieds.Merge(projectNoFundingSourceAmountsUpdated,
                                                           allProjectNoFundingSourceIdentifieds,
                                                           (x, y) => x.ProjectID == y.ProjectID && x.CalendarYear == y.CalendarYear,
                                                           (x, y) => x.NoFundingSourceIdentifiedYet = y.NoFundingSourceIdentifiedYet, databaseEntities);

            var currentProjectRelevantCostTypes = project.GetBudgetsRelevantCostTypes();
            var allProjectRelevantCostTypes     = databaseEntities.AllProjectRelevantCostTypes.Local;
            var projectRelevantCostTypes        = new List <ProjectRelevantCostType>();

            if (ProjectRelevantCostTypes != null)
            {
                // Completely rebuild the list
                projectRelevantCostTypes =
                    ProjectRelevantCostTypes.Where(x => x.IsRelevant)
                    .Select(x => new ProjectRelevantCostType(x.ProjectRelevantCostTypeID, x.ProjectID, x.CostTypeID, ProjectRelevantCostTypeGroup.Budgets.ProjectRelevantCostTypeGroupID))
                    .ToList();
            }
            currentProjectRelevantCostTypes.Merge(projectRelevantCostTypes,
                                                  allProjectRelevantCostTypes,
                                                  (x, y) => x.ProjectID == y.ProjectID && x.CostTypeID == y.CostTypeID && x.ProjectRelevantCostTypeGroupID == y.ProjectRelevantCostTypeGroupID, databaseEntities);
        }
Example #3
0
        public void UpdateModel(ProjectUpdateBatch projectUpdateBatch, DatabaseEntities databaseEntities)
        {
            var currentProjectFundingSourceBudgetUpdates = projectUpdateBatch.ProjectFundingSourceBudgetUpdates.ToList();

            databaseEntities.ProjectFundingSourceBudgetUpdates.Load();
            var allProjectFundingSourceBudgetUpdates           = databaseEntities.AllProjectFundingSourceBudgetUpdates.Local;
            var currentProjectNoFundingSourceIdentifiedUpdates = projectUpdateBatch.ProjectNoFundingSourceIdentifiedUpdates.ToList();

            databaseEntities.ProjectNoFundingSourceIdentifiedUpdates.Load();
            var allProjectNoFundingSourceIdentifiedUpdates = HttpRequestStorage.DatabaseEntities.AllProjectNoFundingSourceIdentifiedUpdates.Local;

            projectUpdateBatch.ProjectUpdate.FundingTypeID = FundingTypeID;
            projectUpdateBatch.ExpectedFundingUpdateNote   = ExpectedFundingUpdateNote;

            var projectFundingSourceBudgetUpdatesUpdated = new List <ProjectFirmaModels.Models.ProjectFundingSourceBudgetUpdate>();

            if (ProjectFundingSourceBudgets != null)
            {
                // Completely rebuild the list
                projectFundingSourceBudgetUpdatesUpdated = ProjectFundingSourceBudgets.Where(x => x.IsRelevant ?? false).SelectMany(x => x.ToProjectFundingSourceBudgetUpdates(projectUpdateBatch)).ToList();
            }
            currentProjectFundingSourceBudgetUpdates.Merge(projectFundingSourceBudgetUpdatesUpdated,
                                                           allProjectFundingSourceBudgetUpdates,
                                                           (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.FundingSourceID == y.FundingSourceID && x.CostTypeID == y.CostTypeID && x.CalendarYear == y.CalendarYear,
                                                           (x, y) => x.SetProjectedAmount(y.ProjectedAmount), databaseEntities);

            var projectNoFundingSourceIdentifiedUpdatesUpdated = new List <ProjectNoFundingSourceIdentifiedUpdate>();

            if (FundingTypeID == FundingType.BudgetSameEachYear.FundingTypeID && NoFundingSourceAmounts != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceIdentifiedUpdatesUpdated = NoFundingSourceAmounts.Select(x =>
                                                                                               new ProjectNoFundingSourceIdentifiedUpdate(projectUpdateBatch.ProjectUpdateBatchID, x.CostTypeID)
                {
                    NoFundingSourceIdentifiedYet = x.Amount
                })
                                                                 .ToList();
            }
            else if (FundingTypeID == FundingType.BudgetVariesByYear.FundingTypeID && NoFundingSourceAmounts != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceIdentifiedUpdatesUpdated = NoFundingSourceAmounts.Select(x =>
                                                                                               new ProjectNoFundingSourceIdentifiedUpdate(projectUpdateBatch.ProjectUpdateBatchID, x.CostTypeID)
                {
                    CalendarYear = x.CalendarYear, NoFundingSourceIdentifiedYet = x.Amount
                })
                                                                 .ToList();
            }

            // ReSharper disable once IdentifierTypo
            foreach (var pnfsi in projectNoFundingSourceIdentifiedUpdatesUpdated)
            {
                // ReSharper disable thrice StringLiteralTypo
                Debug.WriteLine($"pnfsi: pnfsi.ProjectUpdateBatchID: {pnfsi.ProjectUpdateBatchID} - pnfsi.CalendarYear: {pnfsi.CalendarYear} pnfsi.CostTypeID: {pnfsi.CostTypeID} pnfsi.NoFundingSourceIdentifiedYet (amount): {pnfsi.NoFundingSourceIdentifiedYet}");
            }

            currentProjectNoFundingSourceIdentifiedUpdates.Merge(projectNoFundingSourceIdentifiedUpdatesUpdated,
                                                                 allProjectNoFundingSourceIdentifiedUpdates,
                                                                 (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID &&
                                                                 x.CalendarYear == y.CalendarYear &&
                                                                 x.CostTypeID == y.CostTypeID,
                                                                 (x, y) => x.NoFundingSourceIdentifiedYet = y.NoFundingSourceIdentifiedYet, databaseEntities);

            var currentProjectUpdateRelevantCostTypes = projectUpdateBatch.GetBudgetsRelevantCostTypes();
            var allProjectRelevantCostTypeUpdates     = databaseEntities.AllProjectRelevantCostTypeUpdates.Local;
            var projectRelevantCostTypeUpdates        = new List <ProjectRelevantCostTypeUpdate>();

            if (ProjectRelevantCostTypes != null)
            {
                // Completely rebuild the list
                projectRelevantCostTypeUpdates =
                    ProjectRelevantCostTypes.Where(x => x.IsRelevant)
                    .Select(x => new ProjectRelevantCostTypeUpdate(x.ProjectRelevantCostTypeID, projectUpdateBatch.ProjectUpdateBatchID, x.CostTypeID, ProjectRelevantCostTypeGroup.Budgets.ProjectRelevantCostTypeGroupID))
                    .ToList();
            }
            currentProjectUpdateRelevantCostTypes.Merge(projectRelevantCostTypeUpdates,
                                                        allProjectRelevantCostTypeUpdates,
                                                        (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.CostTypeID == y.CostTypeID && x.ProjectRelevantCostTypeGroupID == y.ProjectRelevantCostTypeGroupID, databaseEntities);
        }