61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using System.Linq;
|
|
using AutoMapper;
|
|
using LeafWeb.Core.Entities;
|
|
|
|
namespace LeafWeb.Web.ViewModels.LeafOutput
|
|
{
|
|
public class LeafOutputViewModel
|
|
{
|
|
private static readonly IMapper Mapper;
|
|
|
|
public int LeafInputFileId { get; set; }
|
|
public string LeafInputFilename { get; set; }
|
|
public string CurrentStatus { get; set; }
|
|
public string[] ErrorMessages { get; set; }
|
|
public string[] LeafOutputFilenames { get; set; }
|
|
public bool HasLeafChartOutputFile { get; set; }
|
|
public string LeafInputName { get; set; }
|
|
public string LeafInputIdentifier { get; set; }
|
|
public string LeafInputSiteId { get; set; }
|
|
public string LeafInputPhotosynthesisType { get; set; }
|
|
|
|
static LeafOutputViewModel()
|
|
{
|
|
var config =
|
|
new MapperConfiguration(cfg =>
|
|
{
|
|
cfg.CreateMap<LeafInputFile, LeafOutputViewModel>()
|
|
.ForMember(dest => dest.LeafInputFileId, opt => opt.MapFrom(src => src.Id))
|
|
.ForMember(dest => dest.LeafInputFilename, opt => opt.MapFrom(src => src.Filename))
|
|
.ForMember(dest => dest.LeafOutputFilenames,
|
|
opt => opt.ResolveUsing(
|
|
file =>
|
|
file.LeafOutputFiles?
|
|
.Select(o => o.Filename)
|
|
.ToArray()
|
|
?? new string[] {}))
|
|
.ForMember(dest => dest.HasLeafChartOutputFile,
|
|
opt => opt.ResolveUsing(
|
|
file => file.LeafOutputFiles?.Any(o => o.IsLeafChartFile)))
|
|
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.LeafInput.Name))
|
|
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
|
|
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
|
|
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.LeafInput.PhotosynthesisType.Name))
|
|
.ForMember(dest => dest.ErrorMessages,
|
|
opt => opt.ResolveUsing(
|
|
src =>
|
|
src.StatusHistory?
|
|
.Where(sh => sh.Status == LeafInputStatusType.Error)
|
|
.Select(sh => sh.Description)
|
|
.ToArray()
|
|
?? new string[] {}));
|
|
});
|
|
Mapper = config.CreateMapper();
|
|
}
|
|
|
|
public LeafOutputViewModel(LeafInputFile leafInput)
|
|
{
|
|
Mapper.Map(leafInput, this);
|
|
}
|
|
}
|
|
} |