MappingProfile.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using AutoMapper;
  2. using Azure;
  3. using Countries.NET;
  4. using Microsoft.AspNetCore.Identity;
  5. using MTWorkHR.Application.Models;
  6. using MTWorkHR.Core.Entities;
  7. using MTWorkHR.Core.Entities.User;
  8. using MTWorkHR.Core.Global;
  9. using MTWorkHR.Infrastructure.Entities;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace MTWorkHR.Application.Mapper
  16. {
  17. public class MappingProfile : Profile
  18. {
  19. public MappingProfile() {
  20. //identity user
  21. CreateMap<UserDto, ApplicationUser>()
  22. .ForMember(m => m.UserRoles, op => op.Ignore())
  23. // .ForMember(m => m.UserAttachments, op => op.Ignore())
  24. // .ForMember(m => m.UserAddress, op => op.Ignore())
  25. .ForMember(m => m.Id, op => op.Ignore()
  26. );
  27. CreateMap<ApplicationUser, UserDto>().ForMember(m => m.Password, op => op.Ignore())
  28. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification == null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  29. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle == null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  30. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry == null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  31. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  32. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  33. );
  34. CreateMap<ApplicationUser, UserAllDto>()
  35. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification ==null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  36. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle ==null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  37. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry ==null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  38. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country ==null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  39. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  40. );
  41. CreateMap<UserUpdateDto, ApplicationUser>()
  42. .ForMember(m => m.UserRoles, op => op.Ignore())
  43. // .ForMember(m => m.UserAttachments, op => op.Ignore())
  44. // .ForMember(m => m.UserAddress, op => op.Ignore())
  45. .ForMember(m => m.Id, op => op.Ignore());
  46. CreateMap<ApplicationUser, UserUpdateDto>().ForMember(m => m.Password, op => op.Ignore());
  47. CreateMap<UserDto, UserUpdateDto>().ReverseMap();
  48. CreateMap<UserBasicInfoDto, ApplicationUser>().ReverseMap();
  49. CreateMap<UserBasicInfoDto, UserDto>().ReverseMap();
  50. CreateMap<ApplicationUser, ChatUserDto>()
  51. .ForMember(s => s.UserId, o => o.MapFrom(s => s.Id )).ReverseMap();
  52. CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
  53. CreateMap<UserAddress, UserAddressDto>()
  54. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  55. .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
  56. ).ReverseMap();
  57. //identity userRoles
  58. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  59. CreateMap<ApplicationRole, UserRoleDto>()
  60. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  61. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  62. .ReverseMap();
  63. //identity role
  64. CreateMap<RoleDto, ApplicationRole>()
  65. .ForMember(m => m.Id, op => op.Ignore())
  66. .ForMember(m => m.RolePermissions, op => op.Ignore())
  67. ;
  68. CreateMap<ApplicationRole, RoleDto>();
  69. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  70. CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  71. CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  72. CreateMap<UserTaskAttachment, AttachmentDto>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  73. CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  74. CreateMap<UserTask, UserTaskAllDto>()
  75. .ForMember(s => s.AttachmentCount, o => o.MapFrom(s => s.TaskAttachments == null ? 0 : s.TaskAttachments.Count))
  76. .ForMember(s => s.CommentsCount, o => o.MapFrom(s => s.TaskHistories== null ? 0 : s.TaskHistories.Count));
  77. CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  78. CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  79. CreateMap<Team, TeamAllDto>()
  80. .ForMember(s => s.TeamUserCount, o => o.MapFrom(s => s.TeamUsers == null ? 0 : s.TeamUsers.Count));
  81. CreateMap<Project, ProjectDto>()
  82. .ForMember(s => s.ProjectTeamIds, o => o.MapFrom(s => s.ProjectTeams != null ? s.ProjectTeams.Select(u => u.TeamId).ToList() : new List<long>()));
  83. CreateMap<Meeting, MeetingDto>();
  84. CreateMap<MeetingDto , Meeting>()
  85. .ForMember(d => d.CreateDate, o => o.Ignore())
  86. .ForMember(d => d.CreateUser, o => o.Ignore());
  87. CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  88. CreateMap<ProjectTeam, ProjectTeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  89. CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek))
  90. .ForMember(d => d.TotalHours, o => o.MapFrom(s =>(s.CheckInTime.HasValue && s.CheckOutTime.HasValue) ? (s.CheckOutTime.Value - s.CheckInTime.Value).TotalHours:0));
  91. CreateMap<AttendanceDto, Attendance>().ForMember(d => d.CreateDate, o => o.Ignore());
  92. CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  93. CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  94. CreateMap<OrderType, OrderTypeDto>().ReverseMap();
  95. CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
  96. CreateMap<CompanyDto, Company>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  97. CreateMap<Company, CompanyDto>();
  98. CreateMap<CountryLookup, CountryDto>().ReverseMap();
  99. CreateMap<Industry, IndustryDto>().ReverseMap();
  100. CreateMap<JobTitle, JobTitleDto>().ReverseMap();
  101. CreateMap<University, UniversityDto>().ReverseMap();
  102. CreateMap<Qualification, QualificationDto>().ReverseMap();
  103. CreateMap<City, CityDto>().ReverseMap();
  104. CreateMap<UserDto, CompanyUserDto>();
  105. CreateMap<CompanyUserDto, UserDto>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap();
  106. CreateMap<CompanyUserDto, UserUpdateDto>().ReverseMap();
  107. CreateMap<CompanyUserDto, ApplicationUser>()
  108. .ForMember(m => m.UserRoles, op => op.Ignore())
  109. .ForMember(m => m.Id, op => op.Ignore());
  110. CreateMap<CompanyUserDto, ApplicationUser>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email));
  111. CreateMap<ApplicationUser, CompanyUserDto>().ForMember(m => m.Password, op => op.Ignore());
  112. CreateMap<UserTaskStatus, UserTaskStatusDto>().ReverseMap();
  113. CreateMap<ChatMessageDto, ChatMessage>().ReverseMap();
  114. //-----------Contract----
  115. CreateMap<Contract, ContractDto>();
  116. CreateMap<ContractDto, Contract>()
  117. .ForMember(d => d.CreateDate, o => o.Ignore())
  118. .ForMember(d => d.CreateUser, o => o.Ignore());
  119. CreateMap<ContractAllowance, ContractAllowanceDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  120. CreateMap<ContractTask, ContractTaskDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  121. CreateMap<ContractWorkingDay, ContractWorkingDayDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  122. CreateMap<ContractTaskAttachment, ContractTaskAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  123. CreateMap<ProjectStage, ProjectStageDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  124. CreateMap<ProjectStageAttachment, ProjectStageAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
  125. }
  126. }
  127. }