51 lines
2.2 KiB
C#
51 lines
2.2 KiB
C#
#if NET
|
|
using AutoMapper;
|
|
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
|
using DigitalData.MessagingService.Application.Common.Dto;
|
|
using DigitalData.MessagingService.Domain.Entities;
|
|
using DigitalData.MessagingService.Application.Common.Dto.EmailAccounts;
|
|
|
|
namespace DigitalData.MessagingService.Application.Common.Mappings;
|
|
|
|
/// <summary>
|
|
/// AutoMapper profile for Emails
|
|
/// </summary>
|
|
public class EmailMappingProfile : Profile
|
|
{
|
|
public EmailMappingProfile()
|
|
{
|
|
// PublishEmailCommand -> Email
|
|
// Sender is resolved via MediatR in the handler and set separately after mapping.
|
|
CreateMap<PublishEmailCommand, EmailContext>()
|
|
.ForMember(dest => dest.Sender, opt => opt.Ignore())
|
|
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
|
|
|
// PublishEmailViaImapCommand -> EmailContext
|
|
CreateMap<PublishEmailViaImapCommand, EmailContext>()
|
|
.ForMember(dest => dest.Sender, opt => opt.Ignore())
|
|
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
|
|
|
// PublishEmailViaOAuth2Command -> EmailContext
|
|
CreateMap<PublishEmailViaOAuth2Command, EmailContext>()
|
|
.ForMember(dest => dest.Sender, opt => opt.Ignore())
|
|
.ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Attachments));
|
|
|
|
// EmailAccountDto -> EmailAccount
|
|
CreateMap<EmailAccount, EmailAccountDto>();
|
|
CreateMap<EmailAccountModificationDto, EmailAccount>();
|
|
|
|
// ReceivedEmailDto <-> ReceivedEmail
|
|
CreateMap<ReceivedEmailDto, ReceivedEmail>()
|
|
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
|
.ForMember(dest => dest.Account, opt => opt.Ignore());
|
|
CreateMap<ReceivedEmail, ReceivedEmailDto>();
|
|
|
|
// EmailAttachmentDto <-> EmailAttachment
|
|
CreateMap<EmailAttachmentDto, EmailAttachment>()
|
|
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
|
.ForMember(dest => dest.EmailId, opt => opt.Ignore())
|
|
.ForMember(dest => dest.Email, opt => opt.Ignore());
|
|
CreateMap<EmailAttachment, EmailAttachmentDto>();
|
|
}
|
|
}
|
|
#endif |