From 3272dd797549911d9e3bb845221c41ca3acb5529 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Fri, 7 Dec 2012 14:15:54 -0500 Subject: [PATCH] Replace previous log search for log detail page --- Web/Controllers/LogController.cs | 8 +++----- Web/DAL/DataService.cs | 13 +++++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Web/Controllers/LogController.cs b/Web/Controllers/LogController.cs index d757f92..1f925f6 100644 --- a/Web/Controllers/LogController.cs +++ b/Web/Controllers/LogController.cs @@ -85,11 +85,10 @@ namespace MileageTraker.Web.Controllers public ActionResult PreviousDetails(int id) { var log = _dataService.GetLog(id); - var previousLog = _dataService.SearchPreviousLog(log); int logId; - if (previousLog != null) + if (log.VehiclePreviousLog != null) { - logId = previousLog.LogId; + logId = log.VehiclePreviousLog.LogId; } else { @@ -101,8 +100,7 @@ namespace MileageTraker.Web.Controllers public ActionResult NextDetails(int id) { - var log = _dataService.GetLog(id); - var nextLog = _dataService.SearchNextLog(log); + var nextLog = _dataService.GetNextLog(id); int logId; if (nextLog != null) { diff --git a/Web/DAL/DataService.cs b/Web/DAL/DataService.cs index e839eb3..ad0c143 100644 --- a/Web/DAL/DataService.cs +++ b/Web/DAL/DataService.cs @@ -73,10 +73,7 @@ namespace MileageTraker.Web.DAL { var log = _db.Logs.Find(id); - var nextLog = - (from l in _db.Logs - where l.VehiclePreviousLogId == log.LogId - select l).FirstOrDefault(); + var nextLog = GetNextLog(log.LogId); if (nextLog != null) nextLog.VehiclePreviousLog = log.VehiclePreviousLog; @@ -96,6 +93,14 @@ namespace MileageTraker.Web.DAL return _db.Logs.Find(id); } + public Log GetNextLog(int id) + { + return + (from l in _db.Logs + where l.VehiclePreviousLogId == id + select l).FirstOrDefault(); + } + public IEnumerable GetValidLogYears() { return