public static ProjectLabelConfigModel GetProjectLabelConfigModel( PortfolioConfiguration config, PortfolioFieldFlags flags = PortfolioFieldFlags.Read, bool includedOnly = false, IEnumerable <PortfolioLabelConfig> customLabels = null, bool fsaOnly = false) { return(ProjectMapper.Map <ProjectLabelConfigModel>(config, opts => { opts.Items[nameof(PortfolioFieldFlags)] = flags; if (includedOnly) { opts.Items[nameof(PortfolioLabelConfig.Included)] = includedOnly; } if (customLabels != null) { opts.Items[nameof(PortfolioLabelConfig)] = customLabels; } if (fsaOnly) { opts.Items[nameof(PortfolioFieldFlags.FSAOnly)] = fsaOnly; } })); }
private async Task <GetProjectDTO <T> > GetProject <T>(string projectId, bool includeOptions, bool includeHistory, bool includeLastUpdate, bool includeConfig, PortfolioFieldFlags flags = PortfolioFieldFlags.Read, Action <Portfolio> permissionCallback = null) where T : ProjectModel, new() { string portfolio; GetProjectDTO <T> result; var context = ServiceContext.PortfolioContext; var reservation = await context.ProjectReservations .SingleOrDefaultAsync(r => r.ProjectId == projectId); if (reservation == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var query = (from p in context.Projects .IncludeProject() .IncludeLabelConfigs() // Need label configs so can map project data fields where p.ProjectReservation_Id == reservation.Id select p); if (includeHistory || includeLastUpdate) { query = query.IncludeUpdates(); } var project = await query.SingleOrDefaultAsync(); if (project == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (permissionCallback != null) { permissionCallback(project.Reservation.Portfolio); } else { ServiceContext.AssertPermission(project.Reservation.Portfolio); } portfolio = project.Reservation.Portfolio.ViewKey; // Build the result result = new GetProjectDTO <T>() { Project = ProjectModelFactory.GetProjectModel <T>(project, includeHistory, includeLastUpdate) }; if (includeConfig) { var userIsFSA = ServiceContext.UserHasFSAClaim(); result.Config = PortfolioMapper.GetProjectLabelConfigModel(project.Reservation.Portfolio.Configuration, flags: flags, fsaOnly: !userIsFSA); } if (includeOptions) { var config = await portfolioService.GetConfigAsync(portfolio); result.Options = await portfolioService.GetNewProjectOptionsAsync(config, result.Project as ProjectEditViewModel); } return(result); }
private PortfolioLabelConfig Factory(string fieldGroup, string fieldTitle, string fieldName, bool included, bool includedLock, bool adminLock, PortfolioFieldType inputType, PortfolioFieldFlags flags = DefaultCRUD, string options = null) { bool inputTypeLocked; switch (inputType) { case PortfolioFieldType.None: case PortfolioFieldType.Auto: case PortfolioFieldType.FreeText: case PortfolioFieldType.PredefinedList: case PortfolioFieldType.PredefinedSearchableList: case PortfolioFieldType.PredefinedField: case PortfolioFieldType.Date: case PortfolioFieldType.ProjectDate: case PortfolioFieldType.NullableBoolean: case PortfolioFieldType.Percentage: case PortfolioFieldType.Budget: case PortfolioFieldType.SmallFreeTextArea: case PortfolioFieldType.MediumFreeTextArea: case PortfolioFieldType.LargeFreeTextArea: case PortfolioFieldType.ProjectMultiSelect: case PortfolioFieldType.PredefinedMultiList: case PortfolioFieldType.NamedLink: case PortfolioFieldType.LinkedItemList: case PortfolioFieldType.ProjectUpdateText: case PortfolioFieldType.ADUserSearch: case PortfolioFieldType.ADUserMultiSearch: case PortfolioFieldType.Milestones: case PortfolioFieldType.AjaxMultiSearch: inputTypeLocked = true; break; case PortfolioFieldType.OptionList: case PortfolioFieldType.RAGChoice: case PortfolioFieldType.PhaseChoice: case PortfolioFieldType.MultiOptionList: inputTypeLocked = false; break; default: throw new ArgumentException("Not recognised", nameof(inputType)); } if ((flags & DefaultCRUD) == 0) { flags |= DefaultCRUD; } if (fieldGroup == FieldGroupName_Budget) { flags |= FSAOnly; } var group = config.LabelGroups.FirstOrDefault(g => g.Name == fieldGroup); var label = config.Labels.FirstOrDefault(l => l.FieldName == fieldName) ?? new PortfolioLabelConfig(); label.Configuration_Id = config.Portfolio_Id; label.Group = group; label.FieldOrder = fieldOrder++; label.FieldTitle = fieldTitle; label.FieldName = fieldName; label.FieldType = inputType; label.IncludedLock = includedLock; label.AdminOnlyLock = adminLock; label.FieldTypeLocked = inputTypeLocked; if (label.FieldOptions == null) { label.FieldOptions = options; } if (label.Id == 0) { label.Included = included || IncludeAll; } else { // Clear flags to leave alone flags = (flags & ~FilterProject); // Set to the current values flags |= (label.Flags & FilterProject); } label.Flags = flags; return(label); }