Fuel Log Match
This commit is contained in:
@@ -6,7 +6,6 @@ using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Utility;
|
||||
using MileageTraker.Web.ViewModels.FuelLog;
|
||||
using MileageTraker.Web.ViewModels.Log;
|
||||
using ImportUploadViewModel = MileageTraker.Web.ViewModels.FuelLog.ImportUploadViewModel;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
@@ -34,6 +33,7 @@ namespace MileageTraker.Web.Controllers
|
||||
}
|
||||
|
||||
var fuelLogs = DataService.GetFuelLogs();
|
||||
|
||||
//fuelLogs.OrderBy(f => f.FuelLogId);
|
||||
|
||||
//var filteredLogs =
|
||||
@@ -41,7 +41,10 @@ namespace MileageTraker.Web.Controllers
|
||||
// orderby log. descending
|
||||
// select log).ToList();
|
||||
|
||||
var viewModel = new ResultsViewModel(fuelLogs, query, CustomExtensions.YearMonthList(validLogYearMonths));
|
||||
var flvm = from fl in fuelLogs.ToList()
|
||||
select new FuelLogIndexViewModel(fl);
|
||||
|
||||
var viewModel = new ResultsViewModel(flvm, query, CustomExtensions.YearMonthList(validLogYearMonths));
|
||||
|
||||
//Session.Add("FuelLogPage", Request.Url.PathAndQuery);
|
||||
|
||||
@@ -51,10 +54,49 @@ namespace MileageTraker.Web.Controllers
|
||||
public ViewResult Details(int id)
|
||||
{
|
||||
var fuelLog = DataService.GetFuelLog(id);
|
||||
var vm = new FuelLogViewModel(fuelLog);
|
||||
var vm = new FuelLogViewModel(fuelLog) { VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber) };
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
public ViewResult Match(int id)
|
||||
{
|
||||
var fuelLog = DataService.GetFuelLog(id);
|
||||
var fuelLogViewModel = new FuelLogViewModel(fuelLog) {VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber)};
|
||||
|
||||
var logs = from l in DataService.GetPossibleMatchingLogs(fuelLog).ToList()
|
||||
where l != fuelLog.Log
|
||||
let v = DataService.GetVehicle(l.VehicleId)
|
||||
let vm = new LogMatchViewModel(l, v, fuelLogViewModel)
|
||||
orderby vm.MismatchCount ascending
|
||||
select vm;
|
||||
|
||||
var matchViewModel =
|
||||
new MatchViewModel
|
||||
{
|
||||
FuelLog = fuelLogViewModel,
|
||||
MatchedLogs = logs.ToList()
|
||||
};
|
||||
|
||||
if (fuelLog.Log != null)
|
||||
matchViewModel.CurrentlyMatchedLog = new LogMatchViewModel(fuelLog.Log, DataService.GetVehicle(fuelLog.Log.VehicleId), fuelLogViewModel);
|
||||
|
||||
// When creating a new Log to match the fuel log, this holds the ID between actions
|
||||
TempData["FuelLogId"] = id;
|
||||
|
||||
return View(matchViewModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Match(int fuelLogId, int logId)
|
||||
{
|
||||
var fuelLog = DataService.GetFuelLog(fuelLogId);
|
||||
var log = DataService.GetLog(logId);
|
||||
fuelLog.Log = log;
|
||||
DataService.UpdateFuelLog(fuelLog);
|
||||
|
||||
return RedirectToAction("Match", new {id = fuelLogId});
|
||||
}
|
||||
|
||||
#region Import
|
||||
|
||||
public ActionResult ImportUpload()
|
||||
@@ -114,7 +156,7 @@ namespace MileageTraker.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Match(int fuelLogId)
|
||||
public ActionResult ImportMatch(int fuelLogId)
|
||||
{
|
||||
var fuelLog = DataService.GetFuelLog(fuelLogId);
|
||||
if (fuelLog == null)
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace MileageTraker.Web.Controllers
|
||||
orderby log.Created descending
|
||||
select log).ToList();
|
||||
|
||||
|
||||
var viewModel = new LogResultsViewModel(filteredLogs, query, CustomExtensions.YearMonthList(validLogYearMonths));
|
||||
|
||||
Session.Add("LogPage", Request.Url.PathAndQuery);
|
||||
@@ -162,7 +161,21 @@ namespace MileageTraker.Web.Controllers
|
||||
DataService.AddLog(log);
|
||||
|
||||
TempData["StatusMessage"] = "Log created";
|
||||
return RedirectToAction("Index");
|
||||
|
||||
if (TempData.ContainsKey("FuelLogId"))
|
||||
{
|
||||
// update fuel log
|
||||
var fuelLogId = (int)TempData["FuelLogId"];
|
||||
var fuelLog = DataService.GetFuelLog(fuelLogId);
|
||||
fuelLog.Log = log;
|
||||
DataService.UpdateFuelLog(fuelLog);
|
||||
|
||||
// return to the fuel log match page
|
||||
TempData["StatusMessage"] = "Log created and matched to the fuel log";
|
||||
return RedirectToAction("Match", "FuelLog", new {id = fuelLogId});
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
viewModel.Purpose.Available = GetPurposeTypesSelectList();
|
||||
|
||||
Reference in New Issue
Block a user