summaryrefslogtreecommitdiff
path: root/Profiles
diff options
context:
space:
mode:
Diffstat (limited to 'Profiles')
-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