Cleanup and fixes
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.Account
|
||||
{
|
||||
public class ChangePasswordViewModel
|
||||
{
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public string Username { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public string FullName { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Current password")]
|
||||
@@ -20,5 +30,22 @@ namespace MileageTraker.Web.ViewModels.Account
|
||||
[Display(Name = "Confirm new password")]
|
||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
|
||||
static ChangePasswordViewModel()
|
||||
{
|
||||
Mapper.CreateMap<Models.User, ChangePasswordViewModel>();
|
||||
}
|
||||
|
||||
public ChangePasswordViewModel(){}
|
||||
|
||||
public ChangePasswordViewModel(Models.User user)
|
||||
{
|
||||
Mapper.Map(user, this);
|
||||
}
|
||||
|
||||
public void SetProperties(Models.User user)
|
||||
{
|
||||
Mapper.Map(user, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
public MileageLogTypeWrapper LogType { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Display(Name = "City Name")]
|
||||
[Display(Name = "Destination City")]
|
||||
[InputSize("medium")]
|
||||
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||
public string CityName { get; set; }
|
||||
@@ -64,6 +64,12 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
||||
Mapper.CreateMap<CreateLogViewModel, Models.Log>();
|
||||
}
|
||||
|
||||
public CreateLogViewModel()
|
||||
{
|
||||
// view will crash if this isn't instantiated
|
||||
LogType = new MileageLogTypeWrapper();
|
||||
}
|
||||
|
||||
public Models.Log GetLog()
|
||||
{
|
||||
var log = new Models.Log();
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ using MileageTraker.Web.ViewModels.Log;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels
|
||||
{
|
||||
public class EmployeeMileageViewModel
|
||||
public class DriverMileageViewModel
|
||||
{
|
||||
public IEnumerable<EmployeeMileageItem> Items { get; set; }
|
||||
public LogQueryViewModel Query { get; set; }
|
||||
@@ -12,7 +12,7 @@ namespace MileageTraker.Web.ViewModels
|
||||
public int TotalMiles { get { return Items.Sum(i => i.Miles); } }
|
||||
public double TotalGasPurchased { get { return Items.Sum(i => i.GasPurchased); } }
|
||||
|
||||
public EmployeeMileageViewModel(IEnumerable<EmployeeMileageItem> items, LogQueryViewModel query)
|
||||
public DriverMileageViewModel(IEnumerable<EmployeeMileageItem> items, LogQueryViewModel query)
|
||||
{
|
||||
Items = items;
|
||||
Query = query;
|
||||
@@ -81,6 +81,8 @@ namespace MileageTraker.Web.ViewModels.Log
|
||||
|
||||
public LogViewModel()
|
||||
{
|
||||
// view will crash if this isn't instantiated
|
||||
LogType = new MileageLogTypeWrapper();
|
||||
}
|
||||
|
||||
public LogViewModel(Models.Log log)
|
||||
@@ -95,10 +97,9 @@ namespace MileageTraker.Web.ViewModels.Log
|
||||
return log;
|
||||
}
|
||||
|
||||
public void UpdateLog(Models.Log log)
|
||||
public void SetProperties(Models.Log log)
|
||||
{
|
||||
Mapper.DynamicMap(this, log);
|
||||
//TODO use automapper somehow
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace MileageTraker.Web.ViewModels.User
|
||||
public CheckBoxViewModel Roles { get; set; }
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Set password now instead of emailing ")]
|
||||
[Display(Name = "Set password now instead of emailing invitation")]
|
||||
[NoEditLabel]
|
||||
public bool SetPassword { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.User
|
||||
{
|
||||
public class ExportUserViewModel
|
||||
{
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string Roles { get; set; }
|
||||
|
||||
public bool IsLockedOut { get; set; }
|
||||
|
||||
public bool IsApproved { get; set; }
|
||||
|
||||
public string LastActivityDate { get; set; }
|
||||
public string LastLoginDate { get; set; }
|
||||
public string LastPasswordChangedDate { get; set; }
|
||||
|
||||
static ExportUserViewModel()
|
||||
{
|
||||
Mapper.CreateMap<Models.User, ExportUserViewModel>()
|
||||
.ForMember(u => u.Roles,
|
||||
opt => opt.MapFrom(u =>
|
||||
string.Join((", "), u.Roles.Select(r => r.RoleName))));
|
||||
}
|
||||
|
||||
public ExportUserViewModel(Models.User user)
|
||||
{
|
||||
Mapper.Map(user, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user