Files
LeafWeb/Web/ViewModels/LeafOutput/LeafOutputViewModel.cs
T
poprhythm 05b2bfefb1 Display results from Piscal processing
Error handling for Piscal processing
2016-03-07 11:47:55 -05:00

57 lines
1.9 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 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.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);
}
}
}