public EditProjectFundingSourceBudgetByCostTypeViewModel(ProjectFirmaModels.Models.Project project, List <int> calendarYearsToPopulate, List <ProjectRelevantCostTypeSimple> projectRelevantCostTypes) { FundingTypeID = project.FundingTypeID; ProjectRelevantCostTypes = projectRelevantCostTypes; var noFundingSourceAmountSimples = new List <ProjectNoFundingSourceIdentifiedSimple>(); var projectNoFundingSourceIdentifieds = project.ProjectNoFundingSourceIdentifieds.ToList(); if (project.FundingTypeID.HasValue) { switch (project.FundingType.ToEnum) { case FundingTypeEnum.BudgetVariesByYear: { ProjectFundingSourceBudgets = ProjectFundingSourceBudgetsByCostTypeBulk.MakeFromListByCostType(project, calendarYearsToPopulate); noFundingSourceAmountSimples.AddRange(ProjectNoFundingSourceIdentifiedSimple.CreateFromProjectNoFundingSourceIdentifieds(projectNoFundingSourceIdentifieds)); break; } case FundingTypeEnum.BudgetSameEachYear: ProjectFundingSourceBudgets = ProjectFundingSourceBudgetsByCostTypeBulk.MakeFromListByCostType(project, new List <int>()); noFundingSourceAmountSimples.AddRange(ProjectNoFundingSourceIdentifiedSimple.CreateFromProjectNoFundingSourceIdentifieds(projectNoFundingSourceIdentifieds)); break; default: throw new ArgumentOutOfRangeException(); } } NoFundingSourceAmounts = noFundingSourceAmountSimples; }
public ExpectedFundingByCostTypeViewModel(ProjectUpdateBatch projectUpdateBatch, List <int> calendarYearsToPopulate, List <ProjectRelevantCostTypeSimple> projectRelevantCostTypes) { FundingTypeID = projectUpdateBatch.ProjectUpdate.FundingTypeID; ProjectRelevantCostTypes = projectRelevantCostTypes; var calendarYearMonetaryAmounts = new List <CalendarYearMonetaryAmount>(); if (projectUpdateBatch.ProjectUpdate.FundingTypeID.HasValue) { switch (projectUpdateBatch.ProjectUpdate.FundingType.ToEnum) { case FundingTypeEnum.BudgetVariesByYear: { ProjectFundingSourceBudgets = ProjectFundingSourceBudgetsByCostTypeBulk.MakeFromListByCostType(projectUpdateBatch, calendarYearsToPopulate); var projectNoFundingSourceIdentifieds = projectUpdateBatch.ProjectNoFundingSourceIdentifiedUpdates.ToList(); projectNoFundingSourceIdentifieds.ForEach(x => calendarYearMonetaryAmounts.Add(new CalendarYearMonetaryAmount(x.CalendarYear.Value, x.NoFundingSourceIdentifiedYet))); var usedCalendarYears = projectNoFundingSourceIdentifieds.Select(x => x.CalendarYear).ToList(); calendarYearMonetaryAmounts.AddRange(calendarYearsToPopulate.Where(x => !usedCalendarYears.Contains(x)) .ToList().Select(x => new CalendarYearMonetaryAmount(x, 0))); break; } case FundingTypeEnum.BudgetSameEachYear: ProjectFundingSourceBudgets = ProjectFundingSourceBudgetsByCostTypeBulk.MakeFromListByCostType(projectUpdateBatch, new List <int>()); NoFundingSourceIdentifiedYet = projectUpdateBatch.ProjectNoFundingSourceIdentifiedUpdates.FirstOrDefault()?.NoFundingSourceIdentifiedYet; break; default: throw new ArgumentOutOfRangeException(); } } NoFundingSourceAmounts = calendarYearMonetaryAmounts; ExpectedFundingUpdateNote = projectUpdateBatch.ExpectedFundingUpdateNote; Comments = projectUpdateBatch.ExpectedFundingComment; }