diff --git a/Core/DAL/DataService.cs b/Core/DAL/DataService.cs index d4b0626..8e6a5cb 100644 --- a/Core/DAL/DataService.cs +++ b/Core/DAL/DataService.cs @@ -51,6 +51,23 @@ namespace LeafWeb.Core.DAL return _db.LeafInputs.FirstOrDefault(li => li.Id == id); } + public LeafOutputFile GetLeafOutput_ChartFile(int leafInputId) + { + return GetLeafOutput_FilenameLike(leafInputId, LeafOutputFile.Filename_LeafChart); + } + + private LeafOutputFile GetLeafOutput_FilenameLike(int leafInputId, string filename) + { + var leafOutputChartFile = + from leafInput in _db.LeafInputs + where leafInput.Id == leafInputId + from leafOutput in leafInput.OutputFiles + where leafOutput.Filename.Contains(filename) + select leafOutput; + + return leafOutputChartFile.FirstOrDefault(); + } + public LeafInput GetLeafInput(string uniqueToken) { return _db.LeafInputs.FirstOrDefault(li => li.UniqueToken == uniqueToken); diff --git a/Core/Entities/LeafOutputFile.cs b/Core/Entities/LeafOutputFile.cs index f2acb5f..c7fe451 100644 --- a/Core/Entities/LeafOutputFile.cs +++ b/Core/Entities/LeafOutputFile.cs @@ -3,6 +3,11 @@ namespace LeafWeb.Core.Entities { public class LeafOutputFile { + // convention for the filename which LeafCharter uses + public const string Filename_LeafChart = "leafgascomparison"; + public const string Filename_ErrorMessage = "errormessage"; + public const string Filename_WarningMessage = "warningmessage"; + public int Id { get; set; } public virtual LeafInput LeafInput { get; set; } @@ -11,9 +16,8 @@ namespace LeafWeb.Core.Entities public byte[] Contents { get; set; } - // convention for the filename which LeafCharter uses - public bool IsLeafChartFile => Filename?.Contains("leafgascomparison") ?? false; - public bool IsErrorMessage => Filename?.Contains("errormessage") ?? false; - public bool IsWarningMessage => Filename?.Contains("warningmessage") ?? false; + public bool IsLeafChartFile => Filename?.Contains(Filename_LeafChart) ?? false; + public bool IsErrorMessage => Filename?.Contains(Filename_ErrorMessage) ?? false; + public bool IsWarningMessage => Filename?.Contains(Filename_WarningMessage) ?? false; } } diff --git a/Web/Controllers/ChartController.cs b/Web/Controllers/ChartController.cs index c61d4f1..b9dd42c 100644 --- a/Web/Controllers/ChartController.cs +++ b/Web/Controllers/ChartController.cs @@ -21,11 +21,7 @@ namespace LeafWeb.Web.Controllers { public ActionResult Index(int leafInputId) { - var leafOutputFile = - DataService - .GetLeafInput(leafInputId)? - .OutputFiles? - .FirstOrDefault(f => f.IsLeafChartFile); + var leafOutputFile = DataService.GetLeafOutput_ChartFile(leafInputId); if (leafOutputFile == null) throw new ArgumentOutOfRangeException(); // TODO: break @@ -53,13 +49,9 @@ namespace LeafWeb.Web.Controllers public ActionResult ChartCurve(int leafInputId, string curveId) { - var leafOutputFile = - DataService - .GetLeafInput(leafInputId)? - .OutputFiles? - .FirstOrDefault(f => f.IsLeafChartFile); + var leafOutputFile = DataService.GetLeafOutput_ChartFile(leafInputId); - if (leafOutputFile == null) + if (leafOutputFile == null) throw new ArgumentOutOfRangeException(); // TODO: break var curveData = GetCurveData(leafOutputFile.Contents, curveId);