Filter vehicle services

This commit is contained in:
2015-10-12 18:07:20 -04:00
parent 22e4089fba
commit e008bc2242
14 changed files with 227 additions and 119 deletions
+35 -12
View File
@@ -10,6 +10,7 @@ using MileageTraker.Web.ViewModels;
using MileageTraker.Web.ViewModels.FuelLog;
using MileageTraker.Web.ViewModels.Log;
using MileageTraker.Web.ViewModels.Vehicle;
using MileageTraker.Web.ViewModels.VehicleService;
namespace MileageTraker.Web.DAL
{
@@ -661,19 +662,12 @@ namespace MileageTraker.Web.DAL
public static IQueryable<FuelLog> FilterFuelLogs(IQueryable<FuelLog> fuelLogs, FuelLogQueryViewModel query)
{
const int fiscalYearStartMonth = 7;
// date filtering
if (query.FiscalYear.HasValue & query.Month.HasValue)
if (query.Year.HasValue & query.Month.HasValue)
{
var start = new DateTime(query.FiscalYear.Value, query.Month.Value, 1);
var end = start.AddMonths(1);
fuelLogs = fuelLogs.Where(l => l.Date >= start && l.Date < end);
}
else if (query.FiscalYear.HasValue)
{
var start = new DateTime(query.FiscalYear.Value, fiscalYearStartMonth, 1);
var end = start.AddYears(1);
var start = new DateTime(query.Year.Value, query.Month.Value, 1);
var monthRange = query.MonthRange.HasValue ? query.MonthRange.Value : 1;
var end = start.AddMonths(monthRange);
fuelLogs = fuelLogs.Where(l => l.Date >= start && l.Date < end);
}
if (query.Unmatched)
@@ -817,7 +811,7 @@ namespace MileageTraker.Web.DAL
_db.SaveChanges();
}
public IEnumerable<VehicleService> GetVehicleServices()
public IQueryable<VehicleService> GetVehicleServices()
{
var vehicleServices = _db.VehicleServices;
return vehicleServices;
@@ -836,6 +830,35 @@ namespace MileageTraker.Web.DAL
_db.SaveChanges();
}
public IList<DateTime> GetValidVehicleServiceMonths()
{
var months =
from l in GetVehicleServices()
group l by new {l.InvoiceDate.Year, l.InvoiceDate.Month}
into g
select g.Key;
var ym =
from m in months.ToList()
select new DateTime(m.Year, m.Month, 1);
return ym.OrderByDescending(dt => dt).ToList();
}
public static IQueryable<VehicleService> FilterVehicleServices(IQueryable<VehicleService> vehicleServices, VehicleServiceQueryViewModel query)
{
// date filtering
if (query.Year.HasValue & query.Month.HasValue)
{
var start = new DateTime(query.Year.Value, query.Month.Value, 1);
var monthRange = query.MonthRange.HasValue ? query.MonthRange.Value : 1;
var end = start.AddMonths(monthRange);
vehicleServices = vehicleServices.Where(l => l.InvoiceDate >= start && l.InvoiceDate < end);
}
return vehicleServices;
}
#endregion
}
}