summaryrefslogtreecommitdiff
path: root/Profiles/AutomapperProfiles.cs
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-11-06 17:04:29 -0600
committerHombreLaser <sebastian-440@live.com>2022-11-06 17:04:29 -0600
commit8b40d27710e532a43aaf1eb198be64af1a2e576e (patch)
treecd2264d249e7cb4d1a9e3407d36d0db9680ef913 /Profiles/AutomapperProfiles.cs
parent08819c6738a4f82ccf07ae5ed60835b087f7bb34 (diff)
Añadidos DTOs y AutomapperHEADmain
Diffstat (limited to 'Profiles/AutomapperProfiles.cs')
-rw-r--r--Profiles/AutomapperProfiles.cs31
1 files changed, 31 insertions, 0 deletions
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<CreateUserAccount, UserAccount>();
+ CreateMap<UserAccount, UserAccountDTO>().ForMember(dto => dto.Groups, o => o.MapFrom(UserDTOMap));
+ //CreateMap<UserAccountDTO, UserAccount>();
+ CreateMap<CreateGroup, Group>();
+ CreateMap<Group, GroupDTO>().ReverseMap();
+ }
+
+ private List<GroupDTO> UserDTOMap(UserAccount user, UserAccountDTO dto) {
+ List<GroupDTO> groups = new List<GroupDTO>();
+
+ 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