Files
LeafWeb/WebCms/App_Start/AutoMapperConfig.cs
T

57 lines
2.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using LeafWeb.WebCms.Models;
namespace LeafWeb.WebCms.App_Start
{
public static class AutoMapperConfig
{
public static void RegisterMappings()
{
Mapper.CreateMap<LeafInputCreate, LeafInput>()
.ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
Mapper.CreateMap<LeafInput, LeafInputCreate>()
.ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
// 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<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)));
// LeafInputData
Mapper.CreateMap<LeafInputData, LeafInputDataViewModel>();
// LeafInputDataCurveViewModel
Mapper.CreateMap<LeafInputDataCurve, LeafInputDataCurveViewModel>();
// LeafInputDataSite
Mapper.CreateMap<LeafInputDataSite, LeafInputDataSiteViewModel>();
// LeafInputStatus
Mapper.CreateMap<LeafInputStatus, LeafInputStatusViewModel>()
.ForMember(dest => dest.Status, opt => opt.MapFrom(li => li.Status.ToString()));
//AutoMapper.AutoMapperMappingException {"Missing type map configuration or unsupported mapping.
//
//Mapping types:
//HashSet`1 -> LeafInputData
//System.Collections.Generic.HashSet`1[[LeafWeb.Core.Entities.LeafInputDataCurve, Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> LeafWeb.Core.Entities.LeafInputData
//
//Destination path:
//LeafInputDetails.LeafInputData.LeafInputData.LeafInputData0[0]
//
//Source value:
//System.Collections.Generic.HashSet`1[LeafWeb.Core.Entities.LeafInputDataCurve]"}
Mapper.CreateMap<ICollection<LeafInputDataCurve>, LeafInputData>()
.ForAllMembers(opt => opt.Ignore());
}
}
}