/// <summary> /// Obtient les données pour l'écran Construire. /// </summary> /// <param name="context">Le contexte EF.</param> /// <param name="projectId">L'identifiant du projet.</param> /// <param name="natureFilter">Le filtre sur les codes de nature de scénario.</param> /// <returns>Les données</returns> public static async Task <BuildData> GetBuildData(KsmedEntities context, int projectId, GetDataScenarioNatures natureFilter) { IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await GetReferentialsUse(context, projectId); Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed); BuildData data = new BuildData { Categories = referentials.Categories, Skills = referentials.Skills, Resources = referentials.Resources, Videos = await context.Projects .Include(nameof(Project.Process)) .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}") .Where(p => p.ProjectId == projectId) .SelectMany(p => p.Process.Videos) .ToArrayAsync(), ActionTypes = (await context.ActionTypes.ToArrayAsync()).OrderBy(a => a.ActionTypeCode, new KnownActionCategoryTypes.ActionCategoryTypeDefaultOrderComparer()).ToArray() }; Project project = await context.Projects.SingleAsync(p => p.ProjectId == projectId); data.CustomFieldsLabels = GetCustomFieldsLabels(project); Scenario[] scenarios = await LoadScenarios(context, projectId, referentialsUsed, natureFilter); ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios); data.Scenarios = scenarios; return(data); }
/// <summary> /// Charge les référentiels du projet spécifié dans le contexte. /// </summary> /// <param name="context">Le contexte.</param> /// <param name="projectId">L'identifiant du projet.</param> /// <param name="referentialsUse">Les référentiels utilisés, ou <c>null</c> pour les utiliser tous.</param> /// <returns>Les référentiels chargés.</returns> internal static async Task <Referentials> LoadAllReferentialsOfProject(KsmedEntities context, int projectId, IDictionary <ProcessReferentialIdentifier, bool> referentialsUse) { bool isNull = referentialsUse == null; int processId = (await context.Projects.SingleAsync(p => p.ProjectId == projectId)).ProcessId; Referentials results = new Referentials { // Toujours actif Categories = await FilterReferentials(context.ActionCategories, processId, ProcessReferentialIdentifier.Category).ToArrayAsync(), Skills = await FilterReferentials(context.Skills, processId, ProcessReferentialIdentifier.Skill).ToArrayAsync(), Resources = await FilterResources(context, processId).ToArrayAsync() }; if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref1]) { results.Ref1s = await FilterReferentials(context.Refs1, processId, ProcessReferentialIdentifier.Ref1).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref2]) { results.Ref2s = await FilterReferentials(context.Refs2, processId, ProcessReferentialIdentifier.Ref2).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref3]) { results.Ref3s = await FilterReferentials(context.Refs3, processId, ProcessReferentialIdentifier.Ref3).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref4]) { results.Ref4s = await FilterReferentials(context.Refs4, processId, ProcessReferentialIdentifier.Ref4).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref5]) { results.Ref5s = await FilterReferentials(context.Refs5, processId, ProcessReferentialIdentifier.Ref5).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref6]) { results.Ref6s = await FilterReferentials(context.Refs6, processId, ProcessReferentialIdentifier.Ref6).ToArrayAsync(); } if (isNull || referentialsUse[ProcessReferentialIdentifier.Ref7]) { results.Ref7s = await FilterReferentials(context.Refs7, processId, ProcessReferentialIdentifier.Ref7).ToArrayAsync(); } return(results); }
/// <summary> /// Obtient les données pour l'écran Restituer. /// </summary> /// <param name="context">le contexte EF.</param> /// <param name="projectId">L'identifiant du projet.</param> /// <returns> /// Les données /// </returns> public static async Task <RestitutionData> GetRestitutionData(KsmedEntities context, int projectId) { IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await GetReferentialsUse(context, projectId); Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed); ActionCategory[] categories = referentials.Categories; await context.Projects .Include(nameof(Project.Process)) .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}") .Where(p => p.ProjectId == projectId) .SelectMany(p => p.Process.Videos) .ToArrayAsync(); Scenario[] scenarios = await context.Scenarios .Where(s => s.ProjectId == projectId) .ToArrayAsync(); await Queries.LoadScenariosDetails(context, scenarios, referentialsUsed); ILookup <int, KAction> actionsToLoad = scenarios .SelectMany(a => a.Actions) .Where(a => a.IsReduced && a.OriginalActionId.HasValue) .ToLookup(a => a.OriginalActionId.Value, a => a); if (actionsToLoad.Any()) { foreach (ActionDuration duration in await GetActionsBuildDurations(context, actionsToLoad.Select(g => g.Key))) { foreach (KAction action in actionsToLoad[duration.ActionId]) { action.Reduced.Saving = duration.BuildDuration - action.BuildDuration; } } } ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios); foreach (Scenario scenario in scenarios) { UpdateIsGroup(scenario); } RestitutionData data = new RestitutionData() { Scenarios = scenarios, ActionCategories = categories, }; return(data); }
public static async void CheckReferentialsState() { // Règles // 1. Il n'y a pas de référentiel projet utilisé dans un projet différent de celui où il est déclaré // 2. Il n'y a pas de vidéos en POV sans ressource associée using (var context = ContextFactory.GetNewContext()) { Referentials referentials = new Referentials { Categories = await context.ActionCategories.ToArrayAsync(), Resources = await context.Resources.ToArrayAsync(), Ref1s = await context.Refs1.ToArrayAsync(), Ref2s = await context.Refs2.ToArrayAsync(), Ref3s = await context.Refs3.ToArrayAsync(), Ref4s = await context.Refs4.ToArrayAsync(), Ref5s = await context.Refs5.ToArrayAsync(), Ref6s = await context.Refs6.ToArrayAsync(), Ref7s = await context.Refs7.ToArrayAsync() }; // 1. Il n'y a pas de référentiel projet utilisé dans deux projets différents foreach (var category in referentials.Categories.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.CategoryId == category.Id && a.Scenario.Project.ProcessId != category.ProcessId), category.Id.ToString()); } foreach (var resource in referentials.Resources.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.ResourceId == resource.Id && a.Scenario.Project.ProcessId != resource.ProcessId)); Debug.Assert(!await context.Videos.AnyAsync(v => v.DefaultResourceId == resource.Id && v.ProcessId != resource.ProcessId)); } foreach (var ref1 in referentials.Ref1s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref1.Any(ar => ar.RefId == ref1.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref2 in referentials.Ref2s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref2.Any(ar => ar.RefId == ref2.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref3 in referentials.Ref3s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref3.Any(ar => ar.RefId == ref3.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref4 in referentials.Ref4s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref4.Any(ar => ar.RefId == ref4.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref5 in referentials.Ref5s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref5.Any(ar => ar.RefId == ref5.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref6 in referentials.Ref6s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref6.Any(ar => ar.RefId == ref6.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } foreach (var ref7 in referentials.Ref7s.OfType <IActionReferentialProcess>().Where(r => r.ProcessId != null)) { Debug.Assert(!await context.KActions.AnyAsync(a => a.Ref7.Any(ar => ar.RefId == ref7.Id) && a.Scenario.Project.ProcessId != a.Scenario.Project.ProcessId)); } // 2. Il n'y a pas de vidéos avec une vue sans ressource associée Debug.Assert(!await context.Videos.AnyAsync(v => v.ResourceView != null && v.DefaultResourceId == null)); } }