MappingProfile.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using AutoMapper;
  2. using Microsoft.AspNetCore.Identity;
  3. using MTWorkHR.Application.Models;
  4. using MTWorkHR.Core.Entities;
  5. using MTWorkHR.Core.Entities.User;
  6. using MTWorkHR.Core.Global;
  7. using MTWorkHR.Infrastructure.Entities;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace MTWorkHR.Application.Mapper
  14. {
  15. public class MappingProfile : Profile
  16. {
  17. public MappingProfile() {
  18. //identity user
  19. CreateMap<UserDto, ApplicationUser>()
  20. .ForMember(m => m.UserRoles, op => op.Ignore())
  21. .ForMember(m => m.Id, op => op.Ignore());
  22. CreateMap<ApplicationUser, UserDto>().ForMember(m => m.Password, op => op.Ignore());
  23. CreateMap<ApplicationUser, UserAllDto>()
  24. .ForMember(s => s.ManagerName, o => o.MapFrom(s => s.Manager.FirstName)
  25. //.ForMember(s => s.DepartmentName, o => o.MapFrom(s => GlobalInfo.lang == "ar" ? s.Department.NameAr : s.Department.NameEn)
  26. );
  27. CreateMap<UserUpdateDto, ApplicationUser>()
  28. .ForMember(m => m.UserRoles, op => op.Ignore())
  29. // .ForMember(m => m.UserBranchs, op => op.Ignore())
  30. // .ForMember(m => m.UserCycleApprovals, op => op.Ignore())
  31. //.ForMember(m => m.Hierarchies, op => op.Ignore())
  32. .ForMember(m => m.Id, op => op.Ignore());
  33. CreateMap<ApplicationUser, UserUpdateDto>();
  34. CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
  35. CreateMap<UserAddress, UserAddressDto>().ReverseMap();
  36. //identity userRoles
  37. CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
  38. CreateMap<ApplicationRole, UserRoleDto>()
  39. .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
  40. .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
  41. .ReverseMap();
  42. //identity role
  43. CreateMap<RoleDto, ApplicationRole>()
  44. .ForMember(m => m.Id, op => op.Ignore())
  45. .ForMember(m => m.RolePermissions, op => op.Ignore())
  46. ;
  47. CreateMap<ApplicationRole, RoleDto>();
  48. CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
  49. CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  50. CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  51. CreateMap<UserTaskAttachment, AttachmentDto>().ReverseMap();
  52. CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  53. CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  54. CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
  55. CreateMap<Meeting, MeetingDto>().ReverseMap()
  56. .ForMember(d => d.CreateDate, o => o.Ignore());
  57. CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  58. CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek)).ReverseMap()
  59. .ForMember(d => d.CreateDate, o => o.Ignore());
  60. CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  61. CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  62. CreateMap<OrderType, OrderTypeDto>().ReverseMap();
  63. CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
  64. CreateMap<Company, CompanyDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
  65. }
  66. }
  67. }