public async Task <PortfolioSummaryModel> GetSummaryAsync(string viewKey, string summaryType, string userFilter, string projectTypeFilter, bool includeKeyData = false)
        {
            PortfolioSummaryModel result = null;
            var context   = ServiceContext.PortfolioContext;
            var portfolio = await context.Portfolios
                            .Include(p => p.Teams)
                            .IncludeConfig()
                            .SingleOrDefaultAsync(p => p.ViewKey == viewKey);

            if (portfolio == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (ServiceContext.HasPermission(portfolio))
            {
                if (!string.IsNullOrEmpty(userFilter))
                {
                    TraceSummaryQuery(viewKey, summaryType, userFilter, projectTypeFilter);
                }

                var projectFilter = BuildProjectFilter(userFilter, projectTypeFilter);

                await context.LoadProjectsIntoPortfolioAsync(portfolio, projectFilter);

                result = PortfolioMapper.ConfigMapper.Map <PortfolioSummaryModel>(
                    portfolio,
                    opt =>
                {
                    opt.Items[ProjectIndexDateResolver.OptionKey]     = includeKeyData;
                    opt.Items[ProjectIndexPriorityResolver.OptionKey] = includeKeyData;
                    opt.Items[nameof(PortfolioContext)]                = context;
                    opt.Items[PortfolioPersonResolver.PersonKey]       = userFilter;
                    opt.Items[nameof(PortfolioConfiguration)]          = portfolio.Configuration;
                    opt.Items[PortfolioSummaryResolver.SummaryTypeKey] = summaryType;
                    opt.Items[ProjectActionsResolver.CheckBacklogKey]  = false;
                });
            }
            else
            {
                AppLog.TraceWarning($"Request rejected due to permissions");
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            return(result);
        }
예제 #2
0
        public List <DropDownItemModel> Resolve(Portfolio source, PortfolioSummaryModel destination, List <DropDownItemModel> destMember, ResolutionContext context)
        {
            List <DropDownItemModel> options = null;
            var label = source.Configuration.Labels.SingleOrDefault(l => l.FieldName == ProjectPropertyConstants.project_type);

            if (label != null)
            {
                options = (label.FieldOptions ?? string.Empty).Split(',').Select((o, i) =>
                {
                    var ot = o.Trim();
                    return(new DropDownItemModel()
                    {
                        Order = i + 1,
                        Display = ot,
                        Value = ot
                    });
                }).ToList();
                options.Insert(0, new DropDownItemModel()
                {
                    Order = 0, Display = "All projects"
                });
            }
            return(options);
        }
        public async Task <PortfolioSummaryModel> GetSummaryLabelsAsync(string viewKey)
        {
            PortfolioSummaryModel result = null;
            var context   = ServiceContext.PortfolioContext;
            var portfolio = await context.Portfolios
                            .IncludeConfig()
                            .SingleOrDefaultAsync(p => p.ViewKey == viewKey);

            if (portfolio == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (ServiceContext.HasPermission(portfolio))
            {
                result = PortfolioMapper.ConfigMapper.Map <PortfolioSummaryModel>(portfolio, opt => { });
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            return(result);
        }
예제 #4
0
        public IEnumerable <PortfolioLabelModel> Resolve(Portfolio source, PortfolioSummaryModel destination, IEnumerable <PortfolioLabelModel> destMember, ResolutionContext context)
        {
            var summaryLabels = source.Configuration.Labels.Where(l => summaryFields.Contains(l.FieldName));

            return(context.Mapper.Map <IEnumerable <PortfolioLabelModel> >(summaryLabels));
        }
        public IEnumerable <ProjectSummaryModel> Resolve(Portfolio source, PortfolioSummaryModel destination, IEnumerable <ProjectSummaryModel> destMember, ResolutionContext context)
        {
            IEnumerable <ProjectSummaryModel> result = null;

            if (context.Items.ContainsKey(SummaryTypeKey))
            {
                var summaryType = context.Items[SummaryTypeKey] as string;
                switch (summaryType)
                {
                case PortfolioSummaryModel.ByCategory:
                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(source.Configuration.Categories.OrderBy(c => c.Name));
                    break;

                case PortfolioSummaryModel.ByPriorityGroup:
                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(source.Configuration.PriorityGroups.OrderBy(c => c.Order));
                    break;

                case PortfolioSummaryModel.ByRagStatus:
                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(source.Configuration.RAGStatuses.OrderBy(c => c.Order));
                    break;

                case PortfolioSummaryModel.ByPhase:
                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(source.Configuration.Phases.Where(p => p.Id != source.Configuration.CompletedPhase.Id).OrderBy(c => c.Order));
                    break;

                case PortfolioSummaryModel.ByLead:

                    var people = source.Configuration.Portfolio.Projects
                                 .Where(p => p.Lead_Id != null)
                                 .Select(p => p.Lead)
                                 .Distinct()
                                 .OrderBy(p => p.Firstname)
                                 .ThenBy(p => p.Surname)
                                 .ToList();
                    people.Insert(0, new Person()
                    {
                        Id = 0, ActiveDirectoryDisplayName = ProjectTeamConstants.NotSetName
                    });

                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(people);

                    result = RemoveEmptySummaries(result);

                    break;

                case PortfolioSummaryModel.ByTeam:
                case PortfolioSummaryModel.NewProjectsByTeam:

                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(
                        source.Teams.OrderBy(t => t.Order)
                        .Union(new Team[] { new Team()
                                            {
                                                Name = ProjectTeamConstants.NotSetName, Id = 0
                                            } }));

                    result = RemoveEmptySummaries(result);

                    break;

                case PortfolioSummaryModel.ByUser:

                    result = context.Mapper.Map <IEnumerable <ProjectSummaryModel> >(ProjectUserCategory.All(source.Configuration.Labels));

                    result = RemoveEmptySummaries(result);

                    break;

                default:
                    throw new ArgumentException($"Unrecognised summary type: {summaryType}");
                }
            }
            return(result);
        }