Get export working for Vehicle Service

This commit is contained in:
2015-10-12 20:11:02 -04:00
parent e008bc2242
commit d87f654a20
5 changed files with 30 additions and 8 deletions
+2 -1
View File
@@ -60,7 +60,7 @@ namespace MileageTraker.Web.Controllers
var vm = new FuelLogViewModel(fuelLog) { VehicleId = DataService.GetVehicleIdByTag(fuelLog.TagNumber) };
return View(vm);
}
public ViewResult Match(int id)
{
var fuelLog = DataService.GetFuelLog(id);
@@ -89,6 +89,7 @@ namespace MileageTraker.Web.Controllers
return View(matchViewModel);
}
[ActionLog]
[HttpPost]
public ActionResult Match(int fuelLogId, int logId)
{
@@ -31,6 +31,26 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
[ActionLog]
public ActionResult Export(VehicleServiceQueryViewModel query)
{
var validVehicleServiceYearMonths = DataService.GetValidVehicleServiceMonths();
if (!validVehicleServiceYearMonths.Any()) // this means no logs in DB
return View("Empty");
// default parameter processing
query.SetDefaultParameters(validVehicleServiceYearMonths);
var vehicleServices = DataService.FilterVehicleServices(DataService.GetVehicleServices(), query).ToList();
var filteredServices = vehicleServices.Select(vs => new VehicleServiceViewModel(vs));
var name = string.Format("VehicleServices_{0}", query);
var export = ExcelWriter<VehicleServiceViewModel>.WriteXls(filteredServices, name, name);
return File(export, "application/ms-excel", name + ".xls");
}
public ViewResult Details(int id)
{
var vehicleService = DataService.GetVehicleService(id);
+2 -2
View File
@@ -4,7 +4,7 @@
@{
ViewBag.Title = "Fuel Logs";
var grid = new WebGrid(Model.FuelLogs, rowsPerPage: 45);
var parameters = new {FiscalYear = Model.Year, Model.Month, Model.Unmatched};
var queryParams = new {FiscalYear = Model.Year, Model.Month, Model.Unmatched};
}
@section Scripts {
@@ -31,7 +31,7 @@
<div class="btn-toolbar clearfix">
@Html.ActionLink("Import", "ImportUpload", null, new { @class = "btn" })
@Html.ActionLink("Export", "Export", parameters, new { @class = "btn" })
@Html.ActionLink("Export", "Export", queryParams, new { @class = "btn" })
</div>
<div>
+4 -4
View File
@@ -4,7 +4,7 @@
@{
ViewBag.Title = "Logs";
var grid = new WebGrid(Model.Logs, rowsPerPage: 45);
var parameters = new {Model.Year, Model.Month, Model.LogType, Model.MonthRange, Model.VehicleId, Model.EmployeeName};
var queryParams = new {Model.Year, Model.Month, Model.LogType, Model.MonthRange, Model.VehicleId, Model.EmployeeName};
}
@section Styles {
<link href="@Url.Content("~/Content/VehicleColors.css")" rel="stylesheet" type="text/css" />
@@ -36,16 +36,16 @@
<div class="btn-toolbar clearfix">
@Html.ActionLink("Add New Log", "Create", null, new { @class = "btn" })
@Html.ActionLink("Import", "ImportUpload", null, new { @class = "btn"})
@Html.ActionLink("Export", "Export", parameters, new { @class = "btn" })
@Html.ActionLink("Export", "Export", queryParams, new { @class = "btn" })
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Report <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
@Html.ActionLink("Vehicle Mileage", "MonthlyVehicleMileage", parameters)
@Html.ActionLink("Vehicle Mileage", "MonthlyVehicleMileage", queryParams)
</li>
<li>
@Html.ActionLink("Driver Mileage", "MonthlyDriverMileage", parameters)
@Html.ActionLink("Driver Mileage", "MonthlyDriverMileage", queryParams)
</li>
</ul>
</div>
+2 -1
View File
@@ -3,6 +3,7 @@
@{
ViewBag.Title = "Vehicle Service";
var grid = new WebGrid(Model.ServiceItems, rowsPerPage: 45);
var queryParams = new { Model.Year, Model.Month, Model.MonthRange };
}
@section Scripts {
@@ -29,7 +30,7 @@
<div class="btn-toolbar pull-left">
@Html.ActionLink("Add Service", "Create", null, new{@class="btn"})
@Html.ActionLink("Export", "Export", null, new{@class="btn"})
@Html.ActionLink("Export", "Export", queryParams, new{@class="btn"})
</div>
@grid.GetHtml(columns: