private async Task UpdateRAGStatusOptions(PortfolioConfiguration config) { var context = ServiceContext.PortfolioContext; var labelConfig = config.Labels.Single(l => l.FieldName == ProjectPropertyConstants.rag); int options = int.Parse(labelConfig.FieldOptions); if (config.RAGStatuses.Count != options) { ProjectRAGStatus redAmber, amberGreen; switch (options) { case 6: // Add Red/Amber and Amber/Green and set the order var redAmberMap = SyncMaps.ragMap[RagConstants.RedAmberViewKey]; var amberGreenMap = SyncMaps.ragMap[RagConstants.AmberGreenViewKey]; redAmber = new ProjectRAGStatus() { ViewKey = RagConstants.RedAmberViewKey, Name = redAmberMap.Item1, Order = redAmberMap.Item2 }; amberGreen = new ProjectRAGStatus() { ViewKey = RagConstants.AmberGreenViewKey, Name = amberGreenMap.Item1, Order = amberGreenMap.Item2 }; config.RAGStatuses.Add(redAmber); config.RAGStatuses.Add(amberGreen); break; case 4: // Remove Red/Amber and Amber/Green, map any projects with those RAGs var red = config.RAGStatuses.Single(rag => rag.ViewKey == RagConstants.RedViewKey); var amber = config.RAGStatuses.Single(rag => rag.ViewKey == RagConstants.AmberViewKey); redAmber = config.RAGStatuses.Single(rag => rag.ViewKey == RagConstants.RedAmberViewKey); amberGreen = config.RAGStatuses.Single(rag => rag.ViewKey == RagConstants.AmberGreenViewKey); var redAmberUpdates = await context.ProjectUpdates.Where(u => u.RAGStatus.Id == redAmber.Id).ToListAsync(); foreach (var update in redAmberUpdates) { update.RAGStatus = red; } var amberGreenUpdates = await context.ProjectUpdates.Where(u => u.RAGStatus.Id == amberGreen.Id).ToListAsync(); foreach (var update in amberGreenUpdates) { update.RAGStatus = amber; } context.ProjectRAGStatuses.Remove(redAmber); context.ProjectRAGStatuses.Remove(amberGreen); break; default: throw new ArgumentOutOfRangeException($"The label configuration for fieldname=[{ProjectPropertyConstants.rag}] has an unrecognised value. Should be 3 or 5."); } } }
public Portfolio AddPortfolio(PortfolioContext context, string name, string shortName, string viewKey, string requiredRoles = null) { var portfolio = context.Portfolios .Include(p => p.Configuration.Phases) .Include(p => p.Configuration.OnHoldStatuses) .Include(p => p.Configuration.RAGStatuses) .Include(p => p.Configuration.Categories) .Include(p => p.Configuration.ProjectSizes) .Include(p => p.Configuration.BudgetTypes) .Include(p => p.Configuration.LabelGroups) .Include(p => p.Configuration.Labels) .SingleOrDefault(p => p.ViewKey == viewKey); if (portfolio == null) { portfolio = new Portfolio() { ViewKey = viewKey, Configuration = new PortfolioConfiguration() { Phases = new List <ProjectPhase>(), OnHoldStatuses = new List <ProjectOnHoldStatus>(), RAGStatuses = new List <ProjectRAGStatus>(), Categories = new List <ProjectCategory>(), ProjectSizes = new List <ProjectSize>(), BudgetTypes = new List <BudgetType>(), LabelGroups = new List <PortfolioLabelGroup>(), Labels = new List <PortfolioLabelConfig>(), ArchiveAgeDays = PortfolioSettings.DefaultProjectArchiveAgeDays }, RequiredRoleData = requiredRoles }; context.Portfolios.Add(portfolio); } portfolio.Name = name; portfolio.ShortName = shortName; portfolio.IDPrefix = viewKey.ToUpper(); Action <int> phaseFactory = (o) => { string phaseName; string vk = $"{ViewKeyPrefix.Phase}{o}"; if (!SyncMaps.phaseMap.TryGetValue(new Tuple <string, string>(viewKey, vk), out phaseName)) { phaseName = vk; } var phase = portfolio.Configuration.Phases.SingleOrDefault(p => p.ViewKey == vk); if (phase == null) { phase = new ProjectPhase() { ViewKey = vk, Order = o }; portfolio.Configuration.Phases.Add(phase); } phase.Name = phaseName; }; Func <int, ProjectOnHoldStatus> onHoldFactory = (o) => { string k = $"{ViewKeyPrefix.Status}{o}"; var onhold = portfolio.Configuration.OnHoldStatuses.SingleOrDefault(p => p.ViewKey == k); if (onhold == null) { onhold = new ProjectOnHoldStatus() { ViewKey = k, Order = o }; portfolio.Configuration.OnHoldStatuses.Add(onhold); } onhold.Name = SyncMaps.onholdMap[k]; return(onhold); }; Func <string, ProjectRAGStatus> ragFactory = (k) => { var rag = portfolio.Configuration.RAGStatuses.SingleOrDefault(p => p.ViewKey == k); if (rag == null) { rag = new ProjectRAGStatus() { ViewKey = k }; portfolio.Configuration.RAGStatuses.Add(rag); } rag.Name = SyncMaps.ragMap[k].Item1; rag.Order = SyncMaps.ragMap[k].Item2; return(rag); }; Action <int> categoryFactory = (o) => { string k = $"{ViewKeyPrefix.Category}{o}"; var category = portfolio.Configuration.Categories.SingleOrDefault(p => p.ViewKey == k); if (category == null) { category = new ProjectCategory() { ViewKey = k }; portfolio.Configuration.Categories.Add(category); } var tk = new Tuple <string, string>(viewKey, k); category.Name = SyncMaps.categoryMap.ContainsKey(tk) ? SyncMaps.categoryMap[tk] : SyncMaps.categoryMap[new Tuple <string, string>("odd", k)]; category.Order = o; }; Func <int, BudgetType> budgetTypeFactory = (o) => { string k = $"{ViewKeyPrefix.BudgetType}{o}"; var budgetType = portfolio.Configuration.BudgetTypes.SingleOrDefault(p => p.ViewKey == k); if (budgetType == null) { budgetType = new BudgetType() { ViewKey = k, Order = o }; portfolio.Configuration.BudgetTypes.Add(budgetType); } var tk = new Tuple <string, string>(viewKey, k); budgetType.Name = SyncMaps.budgetTypeMap.ContainsKey(tk) ? SyncMaps.budgetTypeMap[tk] : SyncMaps.budgetTypeMap[new Tuple <string, string>("odd", k)]; budgetType.Order = o; return(budgetType); }; Func <int, ProjectSize> sizeFactory = (o) => { string k = $"{ViewKeyPrefix.ProjectSize}{o}"; var projectSize = portfolio.Configuration.ProjectSizes.SingleOrDefault(p => p.ViewKey == k); if (projectSize == null) { projectSize = new ProjectSize() { ViewKey = k, Order = o }; portfolio.Configuration.ProjectSizes.Add(projectSize); } projectSize.Name = SyncMaps.sizeMap[k]; return(projectSize); }; Func <string, int, PortfolioLabelGroup> labelGroupFactory = (n, go) => { var group = portfolio.Configuration.LabelGroups.SingleOrDefault(p => p.Name == n); if (group == null) { group = new PortfolioLabelGroup() { Name = n }; portfolio.Configuration.LabelGroups.Add(group); } group.Order = go; return(group); }; phaseFactory(0); phaseFactory(1); phaseFactory(2); phaseFactory(3); phaseFactory(4); phaseFactory(5); ragFactory(RagConstants.RedViewKey); ragFactory(RagConstants.AmberViewKey); ragFactory(RagConstants.GreenViewKey); ragFactory(RagConstants.NoneViewKey); onHoldFactory(0); onHoldFactory(1); onHoldFactory(2); onHoldFactory(3); if (SyncMaps.categoryKeyMap.TryGetValue(viewKey, out var categoryLookup)) { for (int i = 0; i < categoryLookup.Keys.Count; i++) { categoryFactory(i); } } sizeFactory(0); sizeFactory(1); sizeFactory(2); sizeFactory(3); sizeFactory(4); // Need to lookup budgettypes based on portfolio view key if (SyncMaps.budgetTypeKeyMap.TryGetValue(viewKey, out var budgetTypeLookup)) { for (int i = 0; i < budgetTypeLookup.Keys.Count; i++) { budgetTypeFactory(i); } } labelGroupFactory(FieldGroupConstants.FieldGroupName_ProjectIDs, 0); labelGroupFactory(FieldGroupConstants.FieldGroupName_AboutTheProject, 1); labelGroupFactory(FieldGroupConstants.FieldGroupName_ProjectTeam, 2); labelGroupFactory(FieldGroupConstants.FieldGroupName_ProjectPlan, 3); labelGroupFactory(FieldGroupConstants.FieldGroupName_ProgressIndicators, 4); labelGroupFactory(FieldGroupConstants.FieldGroupName_Updates, 5); labelGroupFactory(FieldGroupConstants.FieldGroupName_Prioritisation, 6); labelGroupFactory(FieldGroupConstants.FieldGroupName_Budget, 7); labelGroupFactory(FieldGroupConstants.FieldGroupName_FSAProcesses, 8); return(portfolio); }
public IEnumerable <PhaseProjectsModel> Resolve(ProjectRAGStatus source, ProjectSummaryModel destination, IEnumerable <PhaseProjectsModel> destMember, ResolutionContext context) { return(SummaryLinqQuery.GetQuery(source.Configuration, p => p.LatestUpdate.RAGStatus != null && p.LatestUpdate.RAGStatus.Id == source.Id, context)); }