public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var errors = new List <ValidationResult>(); if (ProjectFundingSourceBudgets == null) { ProjectFundingSourceBudgets = new List <ProjectFundingSourceBudgetsByCostTypeBulk>(); } if (FundingTypeID.HasValue && ProjectFundingSourceBudgets.Any()) { // need to make sure there is at least one relevant cost type selected var projectFundingSourceBudgetBulks = ProjectFundingSourceBudgets.Where(x => x.IsRelevant ?? false).ToList(); if (!projectFundingSourceBudgetBulks.Any()) { errors.Add(new ValidationResult($"Select a {FieldDefinitionEnum.CostType.ToType().GetFieldDefinitionLabel()} or remove the {FieldDefinitionEnum.FundingSource.ToType().GetFieldDefinitionLabelPluralized()}")); } } return(errors); }
public decimal?GetTargetedFundingForFundingSources(List <int> fundingSourceIDs) { return(ProjectFundingSourceBudgets.Any(x => fundingSourceIDs.Contains(x.FundingSourceID)) ? (decimal?)ProjectFundingSourceBudgets.Where(x => fundingSourceIDs.Contains(x.FundingSourceID)).Sum(x => x.ProjectedAmount.GetValueOrDefault()) : 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); }
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); }