Nearing feature complete for driver auth
This commit is contained in:
@@ -19,7 +19,7 @@ namespace MileageTraker.Web.ViewModels.Account
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[StringLength(16, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "New password")]
|
||||
public string NewPassword { get; set; }
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels
|
||||
{
|
||||
public class CheckBoxViewModel
|
||||
{
|
||||
public IList<string> Available { get; set; }
|
||||
public string[] Selected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -27,28 +27,29 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
|
||||
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)
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
PreviousOdometer = previousLog.EndOdometer;
|
||||
PreviousDate = previousLog.Date;
|
||||
Miles = endOdometer - previousLog.EndOdometer;
|
||||
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 matchingCity = dataService.GetCitiesCorrected(CityName);
|
||||
|
||||
if (!string.IsNullOrEmpty(matchingCity))
|
||||
CityName = matchingCity;
|
||||
|
||||
var vehicle = dataService.GetVehicle(VehicleId);
|
||||
VehicleColor = vehicle.Color;
|
||||
VehicleType = vehicle.Type;
|
||||
VehicleTagNumber = vehicle.TagNumber;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
[Display(Name = "Type")]
|
||||
[NoEditLabel]
|
||||
public MileageLogTypeWrapper LogType { get; set; }
|
||||
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "City Name")]
|
||||
[InputSize("medium")]
|
||||
@@ -62,17 +62,6 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
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()
|
||||
@@ -94,8 +83,10 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
ValidationResult result = null;
|
||||
try
|
||||
{
|
||||
var dataService = new DataService();
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.Log
|
||||
{
|
||||
public class LogViewModel : IValidatableObject
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int LogId { get; set; }
|
||||
|
||||
[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")]
|
||||
[Remote("ExistsByFullName", "User", ErrorMessage = "User with this name doesn't exist")]
|
||||
[StringLength(128)]
|
||||
[Display(Name = "Driver Name")]
|
||||
[InputSize("medium")]
|
||||
public string UserFullName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "City Name")]
|
||||
[InputSize("medium")]
|
||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||
public string CityName { get; set; }
|
||||
|
||||
[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")]
|
||||
[FormatHint("mm/dd/yyyy")]
|
||||
[InputSize("small")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[Display(Name = "Time Created")]
|
||||
[DisplayFormat(DataFormatString = @"{0:MM/dd/yyyy h:mm tt}")]
|
||||
[HiddenInput]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
static LogViewModel()
|
||||
{
|
||||
Mapper.CreateMap<string, int>().ConvertUsing(Convert.ToInt32);
|
||||
Mapper.CreateMap<string, double>().ConvertUsing(Convert.ToDouble);
|
||||
Mapper.CreateMap<string, DateTime>().ConvertUsing(new DateTimeTypeConverter());
|
||||
Mapper.CreateMap<LogViewModel, Models.Log>();
|
||||
Mapper.CreateMap<Models.Log, LogViewModel>()
|
||||
.ForMember(vm => vm.Date, opt => opt.MapFrom(m => m.Date.ToString("d")));
|
||||
}
|
||||
|
||||
public LogViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public LogViewModel(Models.Log log)
|
||||
{
|
||||
Mapper.Map(log, this);
|
||||
}
|
||||
|
||||
public Models.Log GetLog()
|
||||
{
|
||||
var log = new Models.Log();
|
||||
Mapper.Map(this, log);
|
||||
return log;
|
||||
}
|
||||
|
||||
public void UpdateLog(Models.Log log)
|
||||
{
|
||||
Mapper.DynamicMap(this, log);
|
||||
//TODO use automapper somehow
|
||||
}
|
||||
|
||||
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 chronologyResult = null;
|
||||
try
|
||||
{
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
chronologyResult = new ValidationResult(ex.Message, new [] {"EndOdometer"});
|
||||
}
|
||||
if (chronologyResult != null)
|
||||
yield return chronologyResult;
|
||||
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
var user = dataService.FindUserByFullName(UserFullName);
|
||||
if (user == null)
|
||||
{
|
||||
yield return new ValidationResult("User with this name doesn't exist", new[] { "UserFullName" });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,15 @@ using MileageTraker.Web.Attributes;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.User
|
||||
{
|
||||
public class CreateUserViewModel : RolesViewModel
|
||||
public class CreateUserViewModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(128)]
|
||||
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
|
||||
[InputSize("medium")]
|
||||
[Remote("FullNameAvailable", "User", ErrorMessage = "Name already in use")]
|
||||
public string FullName { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
[InputSize("small")]
|
||||
@@ -17,19 +24,14 @@ namespace MileageTraker.Web.ViewModels.User
|
||||
[DataType(DataType.EmailAddress)]
|
||||
[RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")]
|
||||
[InputSize("large")]
|
||||
[Remote("EmailAvailable", "User", ErrorMessage = "Email already in use")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(128)]
|
||||
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
|
||||
[InputSize("medium")]
|
||||
public string FullName { get; set; }
|
||||
public CheckBoxViewModel Roles { get; set; }
|
||||
|
||||
[Required, DataType(DataType.Password)]
|
||||
[StringLength(16, MinimumLength = 6)]
|
||||
[InputSize("medium")]
|
||||
public string Password { get; set; }
|
||||
[Required]
|
||||
[Display(Name = "Set password now instead of emailing ")]
|
||||
[NoEditLabel]
|
||||
public bool SetPassword { get; set; }
|
||||
|
||||
static CreateUserViewModel()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
@@ -7,10 +6,16 @@ using MileageTraker.Web.Attributes;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.User
|
||||
{
|
||||
public class EditUserViewModel : RolesViewModel
|
||||
public class EditUserViewModel
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public Guid UserId { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(128)]
|
||||
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
|
||||
[InputSize("medium")]
|
||||
public string FullName { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
@@ -23,11 +28,7 @@ namespace MileageTraker.Web.ViewModels.User
|
||||
[InputSize("large")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(128)]
|
||||
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
|
||||
[InputSize("medium")]
|
||||
public string FullName { get; set; }
|
||||
public CheckBoxViewModel Roles { get; set; }
|
||||
|
||||
static EditUserViewModel()
|
||||
{
|
||||
@@ -46,9 +47,9 @@ namespace MileageTraker.Web.ViewModels.User
|
||||
|
||||
public void UpdateUser(Models.User user)
|
||||
{
|
||||
user.Username = this.Username;
|
||||
user.FullName = this.FullName;
|
||||
user.Email = this.Email;
|
||||
user.Username = Username;
|
||||
user.FullName = FullName;
|
||||
user.Email = Email;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.User
|
||||
{
|
||||
public class RolesViewModel
|
||||
{
|
||||
public string[] Roles { get; set; }
|
||||
public IList<string> AvailableRoles { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user