MappingProfile.cs 5.7 KB

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