예제 #1
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.SetSecuredAndTargetedAmounts(y.SecuredAmount, y.TargetedAmount), databaseEntities);

            var projectNoFundingSourceIdentifiedUpdatesUpdated = new List <ProjectNoFundingSourceIdentifiedUpdate>();

            if (FundingTypeID == FundingType.BudgetSameEachYear.FundingTypeID && NoFundingSourceIdentifiedYet != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceIdentifiedUpdatesUpdated.Add(new ProjectNoFundingSourceIdentifiedUpdate(projectUpdateBatch.ProjectUpdateBatchID)
                {
                    NoFundingSourceIdentifiedYet = NoFundingSourceIdentifiedYet
                });
            }
            else if (FundingTypeID == FundingType.BudgetVariesByYear.FundingTypeID && NoFundingSourceAmounts != null)
            {
                // Completely rebuild the list
                projectNoFundingSourceIdentifiedUpdatesUpdated = NoFundingSourceAmounts.Where(x => x.MonetaryAmount.HasValue)
                                                                 .Select(x =>
                                                                         new ProjectNoFundingSourceIdentifiedUpdate(projectUpdateBatch.ProjectUpdateBatchID)
                {
                    CalendarYear = x.CalendarYear, NoFundingSourceIdentifiedYet = x.MonetaryAmount.Value
                })
                                                                 .ToList();
            }
            currentProjectNoFundingSourceIdentifiedUpdates.Merge(projectNoFundingSourceIdentifiedUpdatesUpdated,
                                                                 allProjectNoFundingSourceIdentifiedUpdates,
                                                                 (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.CalendarYear == y.CalendarYear,
                                                                 (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);
        }
예제 #2
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);
        }