using System.Linq; using AutoMapper; using LeafWeb.Core.Entities; namespace LeafWeb.Web.ViewModels.Results { public class ResultStatusViewModel { private static readonly IMapper Mapper; public int LeafInputId { get; set; } public string LeafInputName { get; set; } public string LeafInputIdentifier { get; set; } public string LeafInputSiteId { get; set; } public string LeafInputPhotosynthesisType { get; set; } public bool HasLeafChart { get; set; } public string CurrentStatus { get; set; } //public string[] ErrorMessages { get; set; } //public string[] LeafOutputFilenames { get; set; } //public bool HasLeafChartOutputFile { get; set; } static ResultStatusViewModel() { var config = new MapperConfiguration(cfg => { cfg.CreateMap() .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.LeafOutputFilenames, // opt => opt.ResolveUsing( // src => // src.OutputFiles? // .Select(o => o.Filename) // .ToArray() // ?? new string[] {})) //.ForMember(dest => dest.HasLeafChartOutputFile, // opt => opt.ResolveUsing( // file => file.OutputFiles?.Any(o => o.IsLeafChartFile))) .ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.Name)) .ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.Identifier)) .ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.SiteId)) .ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.PhotosynthesisType.Name)) //.ForMember(dest => dest.ErrorMessages, // opt => opt.ResolveUsing( // src => // src.StatusHistory? // .Where(sh => sh.Status == LeafInputStatusType.Exception) // .Select(sh => sh.Description) // .ToArray() // ?? new string[] {})) ; }); Mapper = config.CreateMapper(); } public ResultStatusViewModel(Core.Entities.LeafInput leafInput) { Mapper.Map(leafInput, this); } } }