Automap viewmodels for details display

This commit is contained in:
2020-07-02 08:55:52 -04:00
parent 2b5de1c4cd
commit 3dedac5591
14 changed files with 300 additions and 206 deletions
+6 -23
View File
@@ -30,7 +30,7 @@ namespace LeafWeb.WebCms.Models
[Required(ErrorMessage = "Name required")]
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Please provide full name")]
public string Name { get; set; }
[Display(Name = "Email address")]
[Required(ErrorMessage = "An email address is required")]
[DataType(DataType.EmailAddress)]
@@ -52,13 +52,6 @@ namespace LeafWeb.WebCms.Models
[Display(Name = "Time In Progress")]
public TimeSpan TimeInProgress { get; set; }
[UIHint("LeafInputDataSiteViewModels")]
public List<LeafInputDataSiteViewModel> Sites { get; set; }
[UIHint("LeafInputStatusViewModels")]
public List<LeafInputStatusViewModel> StatusHistory { get; set; }
[HiddenInput(DisplayValue = false)]
public bool HasLeafChart { get; set; }
@@ -76,22 +69,12 @@ namespace LeafWeb.WebCms.Models
[HiddenInput(DisplayValue = false)]
public bool IsCancellable { get; set; }
[UIHint("LeafInputDataViewModels")]
public List<LeafInputDataViewModel> LeafInputData { get; set; }
static LeafInputDetails()
{
Mapper.CreateMap<LeafInputFile, string>().ConvertUsing(file => file?.Contents.GetString());
Mapper.CreateMap<LeafOutputFile, string>().ConvertUsing(file => file?.FileContents.Contents.GetString());
Mapper.CreateMap<LeafInputStatusType, string>().ConvertUsing(st => st.ToString());
Mapper.CreateMap<LeafInputStatusType, LeafInputStatus>().ConvertUsing(st => new LeafInputStatus());
Mapper.CreateMap<LeafInputStatus, LeafInputStatusViewModel>();
Mapper.CreateMap<LeafInputDataSite, LeafInputDataSiteViewModel>();
Mapper.CreateMap<LeafInput, LeafInputDetails>()
.ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.HasLeafChart,
opt => opt.ResolveUsing(src => src.OutputFiles.Any(o => o.IsLeafChartFile)))
.ForMember(dest => dest.Sites, opt =>
opt.ResolveUsing(li => li.LeafInputData.Select(d => d.Site)));
}
[UIHint("LeafInputStatusViewModels")]
public List<LeafInputStatusViewModel> StatusHistory { get; set; }
public LeafInputDetails(LeafInput leafInput)
{