public CommittedProjects(ICommitted committedRepo, ISections sectionsRepo) { this.committedRepo = committedRepo; this.sectionsRepo = sectionsRepo; List <CommittedEntity> GetAnyProjects(int id, BridgeCareContext db, UserInformationModel userInformation) => committedRepo.GetCommittedProjects(id, db); List <CommittedEntity> GetPermittedProjects(int id, BridgeCareContext db, UserInformationModel userInformation) => committedRepo.GetPermittedCommittedProjects(id, db, userInformation.Name); void SaveAnyProjects(List <CommittedProjectModel> models, BridgeCareContext db, UserInformationModel userInformation) => committedRepo.SaveCommittedProjects(models, db); void SavePermittedProjects(List <CommittedProjectModel> models, BridgeCareContext db, UserInformationModel userInformation) => committedRepo.SavePermittedCommittedProjects(models, db, userInformation.Name); CommittedProjectsGetMethods = new Dictionary <string, CommittedProjectsGetMethod> { [Role.ADMINISTRATOR] = GetAnyProjects, [Role.DISTRICT_ENGINEER] = GetPermittedProjects, [Role.CWOPA] = GetPermittedProjects, [Role.PLANNING_PARTNER] = GetPermittedProjects }; CommittedProjectsSaveMethods = new Dictionary <string, CommittedProjectsSaveMethod> { [Role.ADMINISTRATOR] = SaveAnyProjects, [Role.DISTRICT_ENGINEER] = SavePermittedProjects, [Role.CWOPA] = SavePermittedProjects, [Role.PLANNING_PARTNER] = SavePermittedProjects }; }
/// <summary> /// Save committed projects from the template files /// </summary> /// <param name="httpRequest"></param> /// <param name="db"></param> public void SaveCommittedProjectsFiles(HttpRequest httpRequest, BridgeCareContext db) { if (httpRequest.Files.Count < 1) { throw new ConstraintException("Files Not Found"); } var files = httpRequest.Files; var simulationId = int.Parse(httpRequest.Form.Get("selectedScenarioId")); var networkId = int.Parse(httpRequest.Form.Get("networkId")); var applyNoTreatment = httpRequest.Form.Get("applyNoTreatment") == "1"; var committedProjectModels = new List <CommittedProjectModel>(); for (int i = 0; i < files.Count; i++) { GetCommittedProjectModels(files[i], simulationId, networkId, applyNoTreatment, committedProjectModels, db); committedRepo.SaveCommittedProjects(committedProjectModels, db); } }