/// <summary> /// Compute the project summary, no computation perfomed /// </summary> /// <param name="projectId"></param> /// <returns></returns> public ProjectResult computeProjectResult(int projectId, bool details = false) { //if (damageExtentsIn == null) //bac session // DBManager.NewSession(); // Check if project exists bool _projectExist = ActiveSession.QueryOver <Project>().Where(x => x.Id == projectId).RowCount() > 0; if (!_projectExist) { return(new ProjectResult { Project = ActiveSession.Get <Project>(projectId) ?? new Project() { Id = projectId, Name = ResResult.PRJ_NoProject }, Message = String.Format(ResResult.PRJ_ProjectNotFound, projectId), }); } List <DamageExtent> _damageExtents; _damageExtents = ActiveSession .QueryOver <DamageExtent>() .JoinQueryOver(lm => lm.MappedObject).Where(d => d.Project.Id == projectId) .List() //.OrderBy(de=>de.MappedObject.Objectparameter.ObjectClass.ID) //.OrderBy(de=>de.Intensity.ID) .ToList(); if (!_damageExtents.Any()) { return(new ProjectResult { Project = ActiveSession.Get <Project>(projectId) ?? new Project() { Id = projectId, Name = ResResult.PRJ_NoProject }, //Message = $"\n{ResResult.PRJ_NoDamageExtent}", }); } Project _project = _damageExtents.First().MappedObject.Project; var _response = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, }; //List<NatHazard> hazards = _damageExtents.Select(de => de.Intensity.NatHazard).Distinct().OrderBy(n => n.ID).ToList(); IList <Intensity> _intensityListRaw = ActiveSession .QueryOver <Intensity>() .Where(i => i.Project.Id == projectId) .List <Intensity>(); List <NatHazard> _hazards = _intensityListRaw.Select(i => i.NatHazard).Distinct().OrderBy(n => n.ID).ToList(); var _projectResult = new ProjectResult() { Project = _project, NatHazards = _hazards, ShowDetails = details, }; // loop over natural hazards foreach (NatHazard hazard in _hazards) { List <bool> beforeActions = _intensityListRaw .Where(i => i.NatHazard.ID == hazard.ID) .Select(i => i.BeforeAction) .Distinct() .OrderByDescending(a => a).ToList(); foreach (bool beforeMeasure in beforeActions) { List <IKClasses> ikClasses = _intensityListRaw .Where(i => i.NatHazard.ID == hazard.ID) .Where(i => i.BeforeAction == beforeMeasure) .Select(i => i.IKClasses) .Distinct() .OrderBy(p => p.Value).ToList(); var _processResult = new ProcessResult() { NatHazard = hazard, BeforeAction = beforeMeasure, }; _projectResult.ProcessResults.Add(_processResult); foreach (IKClasses period in ikClasses) { List <DamageExtent> _scenarioDamageExtents = _damageExtents .Where(de => de.Intensity.BeforeAction == beforeMeasure && de.Intensity.NatHazard == hazard && de.Intensity.IKClasses == period) .OrderBy(de => de.MappedObject.Objectparameter.ObjectClass.ID) .ThenBy(de => de.MappedObject.ID) .ToList(); var _scenarioResult = new ScenarioResult() { DamageExtents = _scenarioDamageExtents, NatHazard = hazard, BeforeAction = beforeMeasure, IkClass = period, }; _processResult.ScenarioResults.Add(_scenarioResult); } } } ////////////////////////////////////////////////////////////////////////////////// // Protection Measure var _protectionMeasure = _project.ProtectionMeasure; if (_protectionMeasure != null) { _projectResult.ProtectionMeasure = _protectionMeasure; if (_projectResult.ProtectionMeasure.LifeSpan < 1) { _projectResult.Message += $"\n{String.Format(ResResult.PRJ_LifeSpanError, _projectResult.ProtectionMeasure.LifeSpan)}"; } } // Project Summary // Errors Summary var _damageExtentErrors = _damageExtents .Where(de => de.Log.Trim().ToUpper() != "OK") .OrderBy(de => de.MappedObject.ID) .ThenByDescending(de => de.Intensity.BeforeAction) .ThenBy(de => de.Intensity.NatHazard.ID) .ThenBy(de => de.Intensity.IKClasses.Value) .ThenBy(de => de.Intensity.IntensityDegree) .Select(de => new DamageExtentError { MappedObject = de.MappedObject, Intensity = de.Intensity, Issue = de.Log } ); if (_damageExtentErrors.Any()) { _projectResult.DamageExtentErrors = _damageExtentErrors.ToList(); } return(_projectResult); }