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
@@ -1,39 +1,6 @@
using System;
using System.Collections.Generic;
namespace MileageTraker.Web.ViewModels.VehicleService
{
public class VehicleServiceQueryViewModel
public class VehicleServiceQueryViewModel : DateQueryViewModel
{
public int? Year { get; set; }
public int? Month { get; set; }
public string YearMonthStart {get
{
return string.Format("{0}-{1:00}", Year, Month);
}}
public override string ToString()
{
var v = new List<string>();
if (Year.HasValue && Month.HasValue)
{
var str = YearMonthStart;
v.Add(str);
}
else if (Year.HasValue)
{
v.Add(Year.ToString());
}
return String.Join("_", v).Replace(' ', '-');
}
public bool HasParameters()
{
return Year.HasValue;
}
}
}
@@ -1,9 +1,37 @@
using System.Collections.Generic;
using System.Globalization;
namespace MileageTraker.Web.ViewModels.VehicleService
{
public class VehicleServiceResultsViewModel
{
public IEnumerable<VehicleServiceViewModel> ServiceItems { get; set; }
public Dictionary<string, List<string>> AvailableYearMonths { get; set; }
public IEnumerable<string> SelectedYearMonths
{
get
{
if (!string.IsNullOrEmpty(Year))
return AvailableYearMonths[Year];
return new List<string>();
}
}
// filter parameters
public string Year { get; set; }
public string Month { get; set; }
public string MonthRange { get; set; }
public VehicleServiceResultsViewModel(
IEnumerable<VehicleServiceViewModel> serviceItems,
VehicleServiceQueryViewModel query,
Dictionary<string, List<string>> availableYearMonths)
{
ServiceItems = serviceItems;
AvailableYearMonths = availableYearMonths;
Year = query.Year.HasValue ? query.Year.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
Month = query.Month.HasValue ? query.Month.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
MonthRange = query.MonthRange.HasValue ? query.MonthRange.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
}
}
}