MappingProfile.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using AutoMapper;
  2. using Microsoft.AspNetCore.Identity;
  3. using MTWorkHR.Application.Models;
  4. using MTWorkHR.Core.Global;
  5. using MTWorkHR.Identity.Entities;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace MTWorkHR.Application.MappingProfiles
  12. {
  13. public class MappingProfile : Profile
  14. {
  15. public MappingProfile() {
  16. //identity user
  17. CreateMap<UserDto, ApplicationUser>()
  18. .ForMember(m => m.UserRoles, op => op.Ignore())
  19. .ForMember(m => m.Id, op => op.Ignore());
  20. CreateMap<ApplicationUser, UserDto>();
  21. CreateMap<ApplicationUser, UserAllDto>()
  22. .ForMember(s => s.ManagerName, o => o.MapFrom(s => s.Manager.FirstName)
  23. //.ForMember(s => s.DepartmentName, o => o.MapFrom(s => GlobalInfo.lang == "ar" ? s.Department.NameAr : s.Department.NameEn)
  24. );
  25. CreateMap<UserUpdateDto, ApplicationUser>()
  26. .ForMember(m => m.UserRoles, op => op.Ignore())
  27. // .ForMember(m => m.UserBranchs, op => op.Ignore())
  28. // .ForMember(m => m.UserCycleApprovals, op => op.Ignore())
  29. //.ForMember(m => m.Hierarchies, op => op.Ignore())
  30. .ForMember(m => m.Id, op => op.Ignore());
  31. CreateMap<ApplicationUser, UserUpdateDto>();
  32. CreateMap<UserAttachmentDto, UserAttachment>().ReverseMap();
  33. CreateMap<UserAddress, UserAddressDto>().ReverseMap();
  34. //identity userRoles
  35. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  36. CreateMap<ApplicationRole, UserRoleDto>()
  37. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  38. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  39. .ReverseMap();
  40. //identity role
  41. CreateMap<RoleDto, ApplicationRole>()
  42. .ForMember(m => m.Id, op => op.Ignore())
  43. .ForMember(m => m.RolePermissions, op => op.Ignore())
  44. ;
  45. CreateMap<ApplicationRole, RoleDto>();
  46. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  47. }
  48. }
  49. }