Fuel Log Match
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
{
|
||||
public class FuelLogIndexViewModel
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int FuelLogId { get; set; }
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[StringLength(128)]
|
||||
[Display(Name = "Driver Name")]
|
||||
public string DriverFullName { get; set; }
|
||||
|
||||
[Display(Name = "Tag#")]
|
||||
public string TagNumber { get; set; }
|
||||
|
||||
public int Odometer { get; set; }
|
||||
|
||||
[Display(Name = "MPG")]
|
||||
public double MPG { get; set; }
|
||||
|
||||
[Display(Name = "Gas Purchased")]
|
||||
public double GasPurchased { get; set; }
|
||||
|
||||
[Display(Name = "Total Price")]
|
||||
public decimal TotalPrice { get; set; }
|
||||
|
||||
// Matched log
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int? LogId { get; set; }
|
||||
|
||||
static FuelLogIndexViewModel()
|
||||
{
|
||||
Mapper.CreateMap<Models.FuelLog, FuelLogIndexViewModel>()
|
||||
.ForMember(dest => dest.LogId,
|
||||
opt => opt.ResolveUsing(
|
||||
fl => fl.Log != null ? (int?)fl.Log.LogId : null
|
||||
));
|
||||
}
|
||||
|
||||
public FuelLogIndexViewModel(Models.FuelLog fuelLog)
|
||||
{
|
||||
Mapper.Map(fuelLog, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.ViewModels.Log;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
{
|
||||
@@ -24,6 +25,9 @@ namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
[Display(Name = "Tag#")]
|
||||
public string TagNumber { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public string VehicleId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Odometer { get; set; }
|
||||
|
||||
@@ -54,6 +58,14 @@ namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
opt => opt.ResolveUsing(
|
||||
fl => fl.Log != null ? (int?)fl.Log.LogId : null
|
||||
));
|
||||
|
||||
Mapper.CreateMap<FuelLogViewModel, LogViewModel>()
|
||||
.ForMember(dest => dest.EndOdometer, opt => opt.MapFrom(src => src.Odometer))
|
||||
.ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.CityName))
|
||||
.ForMember(dest => dest.GasPurchased, opt => opt.MapFrom(src => src.GasPurchased))
|
||||
.ForMember(dest => dest.UserFullName, opt => opt.MapFrom(src => src.DriverFullName))
|
||||
.ForMember(dest => dest.VehicleId, opt => opt.MapFrom(src => src.VehicleId))
|
||||
.ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.Date));
|
||||
}
|
||||
|
||||
public FuelLogViewModel(Models.FuelLog fuelLog)
|
||||
@@ -64,5 +76,12 @@ namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
public FuelLogViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public LogViewModel GetLogViewModel()
|
||||
{
|
||||
var logViewModel = new LogViewModel();
|
||||
Mapper.Map(this, logViewModel);
|
||||
return logViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
{
|
||||
public class LogMatchViewModel
|
||||
{
|
||||
public int LogId { get; set; }
|
||||
|
||||
[Display(Name = "Vehicle ID")]
|
||||
public string VehicleId { get; set; }
|
||||
|
||||
public string VehicleTagNumber { get; set; }
|
||||
|
||||
[Display(Name = "End Odometer")]
|
||||
public int EndOdometer { get; set; }
|
||||
|
||||
[Display(Name = "Driver Name")]
|
||||
public string UserFullName { get; set; }
|
||||
|
||||
[Display(Name = "Gas Purchased")]
|
||||
[DisplayFormat(DataFormatString = "{0:0.000}", ApplyFormatInEditMode = true)]
|
||||
public double GasPurchased { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
// indicates an exact match for each of the fields
|
||||
public bool VehicleTagMatch { get; private set; }
|
||||
|
||||
public bool OdometerMatch { get; private set; }
|
||||
|
||||
public bool UserFullNameMatch { get; private set; }
|
||||
|
||||
public bool GasPurchasedMatch { get; private set; }
|
||||
|
||||
public bool DateMatch { get; private set; }
|
||||
|
||||
public int MismatchCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
(VehicleTagMatch ? 0 : 1) +
|
||||
(OdometerMatch ? 0 : 1) +
|
||||
(UserFullNameMatch ? 0 : 1) +
|
||||
(GasPurchasedMatch ? 0 : 1) +
|
||||
(DateMatch ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
static LogMatchViewModel()
|
||||
{
|
||||
Mapper.CreateMap<Models.Log, LogMatchViewModel>();
|
||||
}
|
||||
|
||||
public LogMatchViewModel(Models.Log log, Models.Vehicle vehicle, FuelLogViewModel fuelLog)
|
||||
{
|
||||
Mapper.Map(log, this);
|
||||
VehicleTagNumber = vehicle.TagNumber;
|
||||
|
||||
VehicleTagMatch = VehicleTagNumber == fuelLog.TagNumber;
|
||||
OdometerMatch = log.EndOdometer == fuelLog.Odometer;
|
||||
UserFullNameMatch = string.Equals(log.User.FullName, fuelLog.DriverFullName, StringComparison.InvariantCultureIgnoreCase);
|
||||
GasPurchasedMatch = log.GasPurchased == fuelLog.GasPurchased;
|
||||
DateMatch =
|
||||
log.Date.Year == fuelLog.Date.Year
|
||||
&& log.Date.Month == fuelLog.Date.Month
|
||||
&& log.Date.Day == fuelLog.Date.Day;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
{
|
||||
public class MatchViewModel
|
||||
{
|
||||
public FuelLogViewModel FuelLog { get; set; }
|
||||
public LogMatchViewModel CurrentlyMatchedLog { get; set; }
|
||||
public IList<LogMatchViewModel> MatchedLogs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
{
|
||||
public class ResultsViewModel
|
||||
{
|
||||
public IEnumerable<Models.FuelLog> Logs { get; set; }
|
||||
public IEnumerable<FuelLogIndexViewModel> FuelLogs { get; set; }
|
||||
public Dictionary<string, List<string>> AvailableYearMonths { get; set; }
|
||||
public IEnumerable<string> SelectedYearMonths{get
|
||||
{
|
||||
@@ -18,9 +18,9 @@ namespace MileageTraker.Web.ViewModels.FuelLog
|
||||
public string Year { get; set; }
|
||||
public string Month { get; set; }
|
||||
|
||||
public ResultsViewModel(IEnumerable<Models.FuelLog> logs, FuelLogQueryViewModel query, Dictionary<string, List<string>> availableYearMonths)
|
||||
public ResultsViewModel(IEnumerable<FuelLogIndexViewModel> fuelLogs, FuelLogQueryViewModel query, Dictionary<string, List<string>> availableYearMonths)
|
||||
{
|
||||
Logs = logs;
|
||||
FuelLogs = fuelLogs;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user