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(); CreateMap(); CreateMap(); CreateMap(); CreateMap() .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() .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() .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() .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; } }