Restyle login, change password works
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
{
|
||||
public class ConfirmCreateLogViewModel : CreateLogViewModel
|
||||
{
|
||||
public string VehicleType { get; set; }
|
||||
public string VehicleColor { get; set; }
|
||||
public string VehicleTagNumber { get; set; }
|
||||
public string DateHowLongAgo { get; set; }
|
||||
public int? PreviousOdometer { get; set; }
|
||||
public DateTime? PreviousDate { get; set; }
|
||||
public int? Miles { get; set; }
|
||||
|
||||
static ConfirmCreateLogViewModel()
|
||||
{
|
||||
Mapper.CreateMap<CreateLogViewModel, ConfirmCreateLogViewModel>()
|
||||
.ForMember(c => c.CityName, opt => opt.AddFormatter(new TitleCaseFormatter()))
|
||||
.ForMember(c => c.EmployeeName, opt => opt.AddFormatter(new TitleCaseFormatter()));
|
||||
}
|
||||
|
||||
public ConfirmCreateLogViewModel(CreateLogViewModel createLogViewModel)
|
||||
{
|
||||
Mapper.Map(createLogViewModel, this);
|
||||
|
||||
DateHowLongAgo = (DateTime.Today - Date).ToVerboseStringHistoric();
|
||||
|
||||
var dataService = new DataService();
|
||||
|
||||
var endOdometer = int.Parse(createLogViewModel.EndOdometer);
|
||||
var date = createLogViewModel.Date;
|
||||
|
||||
var previousLog = dataService.SearchPreviousLog(endOdometer, createLogViewModel.VehicleId, date, DateTime.Now);
|
||||
if (previousLog != null)
|
||||
{
|
||||
PreviousOdometer = previousLog.EndOdometer;
|
||||
PreviousDate = previousLog.Date;
|
||||
Miles = endOdometer - previousLog.EndOdometer;
|
||||
}
|
||||
|
||||
var matchingEmployeeName = dataService.GetEmployeeNameCorrected(EmployeeName);
|
||||
|
||||
if (!string.IsNullOrEmpty(matchingEmployeeName))
|
||||
EmployeeName = matchingEmployeeName;
|
||||
|
||||
var matchingCity = dataService.GetCitiesCorrected(CityName);
|
||||
|
||||
if (!string.IsNullOrEmpty(matchingCity))
|
||||
CityName = matchingCity;
|
||||
|
||||
var vehicle = dataService.GetVehicle(VehicleId);
|
||||
VehicleColor = vehicle.Color;
|
||||
VehicleType = vehicle.Type;
|
||||
VehicleTagNumber = vehicle.TagNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
{
|
||||
public class CreateLogViewModel : IValidatableObject
|
||||
{
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Remote("Exists", "Vehicle", ErrorMessage = "ID not found")]
|
||||
[StringLength(6, MinimumLength = 4, ErrorMessage = "Must be a 4 digit number")]
|
||||
[Display(Name = "Vehicle ID")]
|
||||
[InputSize("mini")]
|
||||
[RegularExpression(@"\d+", ErrorMessage = "Must be all numbers")]
|
||||
public string VehicleId { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Range(1, 500000, ErrorMessage = "Between 1 and 500k")]
|
||||
[Display(Name = "End Odometer")]
|
||||
[Units("Miles")]
|
||||
[InputSize("small")]
|
||||
[RegularExpression(@"\d+", ErrorMessage = "Must be all numbers")]
|
||||
public string EndOdometer { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "Type")]
|
||||
[NoEditLabel]
|
||||
public MileageLogTypeWrapper LogType { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "Employee / Driver")]
|
||||
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
|
||||
[InputSize("medium")]
|
||||
public string EmployeeName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "City Name")]
|
||||
[InputSize("medium")]
|
||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||
public string CityName { get; set; }
|
||||
|
||||
[RegularExpression(@"\d+\.\d{3}", ErrorMessage = "Enter all 3 decimal places")]
|
||||
[Display(Name = "Gas Purchased")]
|
||||
[DisplayFormat(DataFormatString = "{0:0.000}", ApplyFormatInEditMode = true)]
|
||||
[Units("Gallons")]
|
||||
[FormatHint("n.nnnn")]
|
||||
[InputSize("mini")]
|
||||
public string GasPurchased { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(DataFormatString = @"{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
|
||||
[DenyFutureDate(ErrorMessage = "Future date")]
|
||||
[DenyPreviousMonthDate(ErrorMessage = "Previous Month")]
|
||||
[FormatHint("mm/dd/yyyy")]
|
||||
[InputSize("small")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
static CreateLogViewModel()
|
||||
{
|
||||
Mapper.CreateMap<string, int>().ConvertUsing(Convert.ToInt32);
|
||||
Mapper.CreateMap<string, double>().ConvertUsing(Convert.ToDouble);
|
||||
Mapper.CreateMap<string, DateTime>().ConvertUsing(new DateTimeTypeConverter());
|
||||
Mapper.CreateMap<CreateLogViewModel, Models.Log>();
|
||||
Mapper.CreateMap<Models.Log, CreateLogViewModel>()
|
||||
.ForMember(vm => vm.Date, opt => opt.MapFrom(m => m.Date.ToString("d")));
|
||||
}
|
||||
|
||||
public CreateLogViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public CreateLogViewModel(Models.Log log)
|
||||
{
|
||||
Mapper.Map(log, this);
|
||||
}
|
||||
|
||||
public Models.Log GetLog()
|
||||
{
|
||||
var log = new Models.Log();
|
||||
Mapper.Map(this, log);
|
||||
return log;
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (LogType == MileageLogType.GasPurchase
|
||||
&& (string.IsNullOrEmpty(GasPurchased) || double.Parse(GasPurchased) == 0))
|
||||
yield return new ValidationResult("Enter amount of gas purchased", new [] {"GasPurchased"});
|
||||
|
||||
if (LogType.Value == 0)
|
||||
yield return new ValidationResult("Required", new[] { "LogType" });
|
||||
|
||||
ValidationResult result = null;
|
||||
try
|
||||
{
|
||||
var dataService = new DataService();
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = new ValidationResult(ex.Message, new [] {"EndOdometer"});
|
||||
}
|
||||
if (result != null)
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user