MappingProfile.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using AutoMapper;
  2. using Microsoft.AspNetCore.Identity;
  3. using MTWorkHR.Application.Models;
  4. using MTWorkHR.Core.Global;
  5. using MTWorkHR.Identity.Models;
  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. //identity userRoles
  33. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  34. CreateMap<ApplicationRole, UserRoleDto>()
  35. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  36. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  37. .ReverseMap();
  38. //identity role
  39. CreateMap<RoleDto, ApplicationRole>()
  40. .ForMember(m => m.Id, op => op.Ignore())
  41. .ForMember(m => m.RolePermissions, op => op.Ignore())
  42. ;
  43. CreateMap<ApplicationRole, RoleDto>();
  44. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  45. }
  46. }
  47. }