MappingProfile.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using AutoMapper;
  2. using Countries.NET;
  3. using Microsoft.AspNetCore.Identity;
  4. using MTWorkHR.Application.Models;
  5. using MTWorkHR.Core.Entities;
  6. using MTWorkHR.Core.Entities.User;
  7. using MTWorkHR.Core.Global;
  8. using MTWorkHR.Infrastructure.Entities;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace MTWorkHR.Application.Mapper
  15. {
  16. public class MappingProfile : Profile
  17. {
  18. public MappingProfile() {
  19. //identity user
  20. CreateMap<UserDto, ApplicationUser>()
  21. .ForMember(m => m.UserRoles, op => op.Ignore())
  22. // .ForMember(m => m.UserAttachments, op => op.Ignore())
  23. // .ForMember(m => m.UserAddress, op => op.Ignore())
  24. .ForMember(m => m.Id, op => op.Ignore()
  25. );
  26. CreateMap<ApplicationUser, UserDto>().ForMember(m => m.Password, op => op.Ignore())
  27. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification == null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  28. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle == null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  29. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry == null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  30. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  31. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  32. );
  33. CreateMap<ApplicationUser, UserAllDto>()
  34. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification ==null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  35. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle ==null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  36. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry ==null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  37. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country ==null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  38. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  39. );
  40. CreateMap<UserUpdateDto, ApplicationUser>()
  41. .ForMember(m => m.UserRoles, op => op.Ignore())
  42. // .ForMember(m => m.UserAttachments, op => op.Ignore())
  43. // .ForMember(m => m.UserAddress, op => op.Ignore())
  44. .ForMember(m => m.Id, op => op.Ignore());
  45. CreateMap<ApplicationUser, UserUpdateDto>().ForMember(m => m.Password, op => op.Ignore());
  46. CreateMap<UserDto, UserUpdateDto>().ReverseMap();
  47. CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
  48. CreateMap<UserAddress, UserAddressDto>()
  49. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  50. .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
  51. ).ReverseMap();
  52. //identity userRoles
  53. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  54. CreateMap<ApplicationRole, UserRoleDto>()
  55. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  56. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  57. .ReverseMap();
  58. //identity role
  59. CreateMap<RoleDto, ApplicationRole>()
  60. .ForMember(m => m.Id, op => op.Ignore())
  61. .ForMember(m => m.RolePermissions, op => op.Ignore())
  62. ;
  63. CreateMap<ApplicationRole, RoleDto>();
  64. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  65. CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  66. CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  67. CreateMap<UserTaskAttachment, AttachmentDto>().ReverseMap();
  68. CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  69. CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  70. CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  71. CreateMap<Team, TeamAllDto>()
  72. .ForMember(s => s.TeamUserCount, o => o.MapFrom(s => s.TeamUsers == null ? 0 : s.TeamUsers.Count));
  73. CreateMap<Meeting, MeetingDto>();
  74. CreateMap<MeetingDto , Meeting>()
  75. .ForMember(d => d.CreateDate, o => o.Ignore())
  76. .ForMember(d => d.CreateUser, o => o.Ignore());
  77. CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  78. CreateMap<ProjectTeam, ProjectTeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  79. CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek)).ReverseMap()
  80. .ForMember(d => d.CreateDate, o => o.Ignore());
  81. CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  82. CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  83. CreateMap<OrderType, OrderTypeDto>().ReverseMap();
  84. CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
  85. CreateMap<CompanyDto, Company>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  86. CreateMap<Company, CompanyDto>();
  87. CreateMap<CountryLookup, CountryDto>().ReverseMap();
  88. CreateMap<Industry, IndustryDto>().ReverseMap();
  89. CreateMap<JobTitle, JobTitleDto>().ReverseMap();
  90. CreateMap<University, UniversityDto>().ReverseMap();
  91. CreateMap<Qualification, QualificationDto>().ReverseMap();
  92. CreateMap<City, CityDto>().ReverseMap();
  93. CreateMap<UserDto, CompanyUserDto>();
  94. CreateMap<CompanyUserDto, UserDto>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap();
  95. CreateMap<CompanyUserDto, ApplicationUser>()
  96. .ForMember(m => m.UserRoles, op => op.Ignore())
  97. .ForMember(m => m.Id, op => op.Ignore());
  98. CreateMap<CompanyUserDto, ApplicationUser>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email));
  99. CreateMap<ApplicationUser, CompanyUserDto>().ForMember(m => m.Password, op => op.Ignore());
  100. CreateMap<UserTaskStatus, UserTaskStatusDto>().ReverseMap();
  101. }
  102. }
  103. }