MappingProfile.cs 2.5 KB

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