MappingProfile.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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<AttachmentDto, UserAttachment>().ReverseMap();
  51. CreateMap<UserAddress, UserAddressDto>()
  52. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  53. .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
  54. ).ReverseMap();
  55. //identity userRoles
  56. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  57. CreateMap<ApplicationRole, UserRoleDto>()
  58. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  59. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  60. .ReverseMap();
  61. //identity role
  62. CreateMap<RoleDto, ApplicationRole>()
  63. .ForMember(m => m.Id, op => op.Ignore())
  64. .ForMember(m => m.RolePermissions, op => op.Ignore())
  65. ;
  66. CreateMap<ApplicationRole, RoleDto>();
  67. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  68. CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  69. CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  70. CreateMap<UserTaskAttachment, AttachmentDto>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  71. CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  72. CreateMap<UserTask, UserTaskAllDto>()
  73. .ForMember(s => s.AttachmentCount, o => o.MapFrom(s => s.TaskAttachments == null ? 0 : s.TaskAttachments.Count))
  74. .ForMember(s => s.CommentsCount, o => o.MapFrom(s => s.TaskHistories== null ? 0 : s.TaskHistories.Count));
  75. CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  76. CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  77. CreateMap<Team, TeamAllDto>()
  78. .ForMember(s => s.TeamUserCount, o => o.MapFrom(s => s.TeamUsers == null ? 0 : s.TeamUsers.Count));
  79. CreateMap<Project, ProjectDto>()
  80. .ForMember(s => s.ProjectTeamIds, o => o.MapFrom(s => s.ProjectTeams != null ? s.ProjectTeams.Select(u => u.TeamId).ToList() : new List<long>()));
  81. CreateMap<Meeting, MeetingDto>();
  82. CreateMap<MeetingDto , Meeting>()
  83. .ForMember(d => d.CreateDate, o => o.Ignore())
  84. .ForMember(d => d.CreateUser, o => o.Ignore());
  85. CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  86. CreateMap<ProjectTeam, ProjectTeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  87. CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek))
  88. .ForMember(d => d.TotalHours, o => o.MapFrom(s =>(s.CheckInTime.HasValue && s.CheckOutTime.HasValue) ? (s.CheckOutTime.Value - s.CheckInTime.Value).TotalHours:0));
  89. CreateMap<AttendanceDto, Attendance>().ForMember(d => d.CreateDate, o => o.Ignore());
  90. CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  91. CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  92. CreateMap<OrderType, OrderTypeDto>().ReverseMap();
  93. CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
  94. CreateMap<CompanyDto, Company>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  95. CreateMap<Company, CompanyDto>();
  96. CreateMap<CountryLookup, CountryDto>().ReverseMap();
  97. CreateMap<Industry, IndustryDto>().ReverseMap();
  98. CreateMap<JobTitle, JobTitleDto>().ReverseMap();
  99. CreateMap<University, UniversityDto>().ReverseMap();
  100. CreateMap<Qualification, QualificationDto>().ReverseMap();
  101. CreateMap<City, CityDto>().ReverseMap();
  102. CreateMap<UserDto, CompanyUserDto>();
  103. CreateMap<CompanyUserDto, UserDto>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap();
  104. CreateMap<CompanyUserDto, UserUpdateDto>().ReverseMap();
  105. CreateMap<CompanyUserDto, ApplicationUser>()
  106. .ForMember(m => m.UserRoles, op => op.Ignore())
  107. .ForMember(m => m.Id, op => op.Ignore());
  108. CreateMap<CompanyUserDto, ApplicationUser>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email));
  109. CreateMap<ApplicationUser, CompanyUserDto>().ForMember(m => m.Password, op => op.Ignore());
  110. CreateMap<UserTaskStatus, UserTaskStatusDto>().ReverseMap();
  111. }
  112. }
  113. }