-
Notifications
You must be signed in to change notification settings - Fork 145
/
DefaultAutomapperProfile.cs
28 lines (26 loc) · 1.35 KB
/
DefaultAutomapperProfile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using AutoMapper;
using BeautifulRestApi.Controllers;
using BeautifulRestApi.Models;
namespace BeautifulRestApi.Infrastructure
{
public class DefaultAutomapperProfile : Profile
{
public DefaultAutomapperProfile()
{
CreateMap<ConversationEntity, ConversationResource>()
.ForMember(dest => dest.Self, opt => opt.MapFrom(src => Link.To(
nameof(ConversationsController.GetConversationByIdAsync),
new GetConversationByIdParameters { ConversationId = src.Id })))
.ForMember(dest => dest.Comments, opt => opt.MapFrom(src => Link.ToCollection(
nameof(ConversationsController.GetConversationCommentsByIdAsync),
new GetConversationByIdParameters { ConversationId = src.Id })));
CreateMap<CommentEntity, CommentResource>()
.ForMember(dest => dest.Self, opt => opt.MapFrom(src => Link.To(
nameof(CommentsController.GetCommentByIdAsync),
new GetCommentByIdParameters { CommentId = src.Id })))
.ForMember(dest => dest.Conversation, opt => opt.MapFrom(src => Link.To(
nameof(ConversationsController.GetConversationByIdAsync),
new GetConversationByIdParameters { ConversationId = src.Conversation.Id })));
}
}
}