MappingProfile.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.Id, op => op.Ignore());
  23. CreateMap<ApplicationUser, UserDto>().ForMember(m => m.Password, op => op.Ignore())
  24. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification == null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  25. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle == null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  26. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry == null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  27. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  28. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  29. );
  30. CreateMap<ApplicationUser, UserAllDto>()
  31. .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification ==null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
  32. .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle ==null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
  33. .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry ==null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
  34. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country ==null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  35. .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
  36. );
  37. CreateMap<UserUpdateDto, ApplicationUser>()
  38. .ForMember(m => m.UserRoles, op => op.Ignore())
  39. // .ForMember(m => m.UserBranchs, op => op.Ignore())
  40. // .ForMember(m => m.UserCycleApprovals, op => op.Ignore())
  41. //.ForMember(m => m.Hierarchies, op => op.Ignore())
  42. .ForMember(m => m.Id, op => op.Ignore());
  43. CreateMap<ApplicationUser, UserUpdateDto>();
  44. CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
  45. CreateMap<UserAddress, UserAddressDto>()
  46. .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
  47. .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
  48. ).ReverseMap();
  49. //identity userRoles
  50. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  51. CreateMap<ApplicationRole, UserRoleDto>()
  52. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  53. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  54. .ReverseMap();
  55. //identity role
  56. CreateMap<RoleDto, ApplicationRole>()
  57. .ForMember(m => m.Id, op => op.Ignore())
  58. .ForMember(m => m.RolePermissions, op => op.Ignore())
  59. ;
  60. CreateMap<ApplicationRole, RoleDto>();
  61. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  62. CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  63. CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
  64. CreateMap<UserTaskAttachment, AttachmentDto>().ReverseMap();
  65. CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  66. CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  67. CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  68. CreateMap<Meeting, MeetingDto>();
  69. CreateMap<MeetingDto , Meeting>()
  70. .ForMember(d => d.CreateDate, o => o.Ignore())
  71. .ForMember(d => d.CreateUser, o => o.Ignore());
  72. CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  73. CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek)).ReverseMap()
  74. .ForMember(d => d.CreateDate, o => o.Ignore());
  75. CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  76. CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  77. CreateMap<OrderType, OrderTypeDto>().ReverseMap();
  78. CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
  79. CreateMap<CompanyDto, Company>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
  80. CreateMap<Company, CompanyDto>();
  81. CreateMap<CountryLookup, CountryDto>().ReverseMap();
  82. CreateMap<Industry, IndustryDto>().ReverseMap();
  83. CreateMap<JobTitle, JobTitleDto>().ReverseMap();
  84. CreateMap<University, UniversityDto>().ReverseMap();
  85. CreateMap<Qualification, QualificationDto>().ReverseMap();
  86. CreateMap<City, CityDto>().ReverseMap();
  87. CreateMap<UserDto, CompanyUserDto>();
  88. CreateMap<CompanyUserDto, UserDto>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap();
  89. CreateMap<CompanyUserDto, ApplicationUser>()
  90. .ForMember(m => m.UserRoles, op => op.Ignore())
  91. .ForMember(m => m.Id, op => op.Ignore());
  92. CreateMap<CompanyUserDto, ApplicationUser>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email));
  93. CreateMap<ApplicationUser, CompanyUserDto>().ForMember(m => m.Password, op => op.Ignore());
  94. CreateMap<UserTaskStatus, UserTaskStatusDto>().ReverseMap();
  95. }
  96. }
  97. }