From 8b40d27710e532a43aaf1eb198be64af1a2e576e Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 6 Nov 2022 17:04:29 -0600 Subject: AƱadidos DTOs y Automapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Profiles/AutomapperProfiles.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Profiles/AutomapperProfiles.cs (limited to 'Profiles') diff --git a/Profiles/AutomapperProfiles.cs b/Profiles/AutomapperProfiles.cs new file mode 100644 index 0000000..8d69788 --- /dev/null +++ b/Profiles/AutomapperProfiles.cs @@ -0,0 +1,31 @@ +using AutoMapper; +using LibraryAPI.Models; +using LibraryAPI.DTOs; + +namespace LibraryAPI.Profiles { + public class AutomapperProfiles : Profile { + public AutomapperProfiles() { + CreateMap(); + CreateMap().ForMember(dto => dto.Groups, o => o.MapFrom(UserDTOMap)); + //CreateMap(); + CreateMap(); + CreateMap().ReverseMap(); + } + + private List UserDTOMap(UserAccount user, UserAccountDTO dto) { + List groups = new List(); + + if(user.Groups == null) + return groups; + + foreach (var g in user.Groups) { + groups.Add(new GroupDTO { + Id = g.GroupId, + Name = g.Group.Name + }); + } + + return groups; + } + } +} \ No newline at end of file -- cgit v1.2.3