WorkFlow/src/WorkFlow.Application/MappingProfile.cs
2025-08-03 11:33:42 +02:00

40 lines
1.7 KiB
C#

using System.Web;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.Dto;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application;
public class MappingProfile : AutoMapper.Profile
{
public MappingProfile()
{
// Mapping entity to DTO
CreateMap<Config, ConfigDto>();
CreateMap<Profile, ProfileDto>();
CreateMap<PControlsTF, PControlsTFDto>();
CreateMap<Button, ButtonDto>();
CreateMap<PObject, ObjectDto>()
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src => new[] { src.Headline1, src.Headline2 }))
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src => new[] { src.Subline1, src.Subline2 }));
CreateMap<PObjectState, ObjectStateDto>()
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
CreateMap<PObjectStateHist, ObjectStateHistDto>()
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
CreateMap<TfFile, TfFileDto>()
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => UriBuilder.WithPath(src.Path, true)));
}
public static UriBuilder UriBuilder { get; set; } = new UriBuilder();
}
internal static class HttpUtilityExtensions
{
public static UriBuilder WithPath(this UriBuilder builder, string path, bool encode = true)
{
builder.Path = encode ? HttpUtility.UrlEncode(path) : path;
return builder;
}
}