123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using AutoMapper;
- using Azure;
- using Countries.NET;
- using Microsoft.AspNetCore.Identity;
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.Entities;
- using MTWorkHR.Core.Entities.User;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Infrastructure.Entities;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MTWorkHR.Application.Mapper
- {
- public class MappingProfile : Profile
- {
- public MappingProfile() {
- //identity user
- CreateMap<UserDto, ApplicationUser>()
- .ForMember(m => m.UserRoles, op => op.Ignore())
- // .ForMember(m => m.UserAttachments, op => op.Ignore())
- // .ForMember(m => m.UserAddress, op => op.Ignore())
- .ForMember(m => m.Id, op => op.Ignore()
- );
- CreateMap<ApplicationUser, UserDto>().ForMember(m => m.Password, op => op.Ignore())
- .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification == null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
- .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle == null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
- .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry == null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
- .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
- .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
- );
- CreateMap<ApplicationUser, UserAllDto>()
- .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification ==null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
- .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle ==null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
- .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry ==null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
- .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country ==null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
- .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
- );
-
- CreateMap<UserUpdateDto, ApplicationUser>()
- .ForMember(m => m.UserRoles, op => op.Ignore())
- // .ForMember(m => m.UserAttachments, op => op.Ignore())
- // .ForMember(m => m.UserAddress, op => op.Ignore())
- .ForMember(m => m.Id, op => op.Ignore());
- CreateMap<ApplicationUser, UserUpdateDto>().ForMember(m => m.Password, op => op.Ignore());
- CreateMap<UserDto, UserUpdateDto>().ReverseMap();
- CreateMap<UserBasicInfoDto, ApplicationUser>().ReverseMap();
- CreateMap<UserBasicInfoDto, UserDto>().ReverseMap();
- CreateMap<ApplicationUser, ChatUserDto>()
- .ForMember(s => s.UserId, o => o.MapFrom(s => s.Id )).ReverseMap();
-
- CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
- CreateMap<UserAddress, UserAddressDto>()
- .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
- .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
- ).ReverseMap();
- //identity userRoles
- CreateMap<IdentityUserRole<string>, UserRoleDto>().ReverseMap();
- CreateMap<ApplicationRole, UserRoleDto>()
- .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id))
- .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name))
- .ReverseMap();
- //identity role
- CreateMap<RoleDto, ApplicationRole>()
- .ForMember(m => m.Id, op => op.Ignore())
- .ForMember(m => m.RolePermissions, op => op.Ignore())
- ;
- CreateMap<ApplicationRole, RoleDto>();
- CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
- CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
- CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap();
- CreateMap<UserTaskAttachment, AttachmentDto>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
- CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
- CreateMap<UserTask, UserTaskAllDto>()
- .ForMember(s => s.AttachmentCount, o => o.MapFrom(s => s.TaskAttachments == null ? 0 : s.TaskAttachments.Count))
- .ForMember(s => s.CommentsCount, o => o.MapFrom(s => s.TaskHistories== null ? 0 : s.TaskHistories.Count));
- CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
- CreateMap<Team, TeamAllDto>()
- .ForMember(s => s.TeamUserCount, o => o.MapFrom(s => s.TeamUsers == null ? 0 : s.TeamUsers.Count));
- CreateMap<Project, ProjectDto>()
- .ForMember(s => s.ProjectTeamIds, o => o.MapFrom(s => s.ProjectTeams != null ? s.ProjectTeams.Select(u => u.TeamId).ToList() : new List<long>()));
- CreateMap<Meeting, MeetingDto>();
- CreateMap<MeetingDto , Meeting>()
- .ForMember(d => d.CreateDate, o => o.Ignore())
- .ForMember(d => d.CreateUser, o => o.Ignore());
- CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<ProjectTeam, ProjectTeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek))
- .ForMember(d => d.TotalHours, o => o.MapFrom(s =>(s.CheckInTime.HasValue && s.CheckOutTime.HasValue) ? (s.CheckOutTime.Value - s.CheckInTime.Value).TotalHours:0));
- CreateMap<AttendanceDto, Attendance>().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
- CreateMap<OrderType, OrderTypeDto>().ReverseMap();
- CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
- CreateMap<CompanyDto, Company>().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore());
- CreateMap<Company, CompanyDto>();
- CreateMap<CountryLookup, CountryDto>().ReverseMap();
- CreateMap<Industry, IndustryDto>().ReverseMap();
- CreateMap<JobTitle, JobTitleDto>().ReverseMap();
- CreateMap<University, UniversityDto>().ReverseMap();
- CreateMap<Qualification, QualificationDto>().ReverseMap();
- CreateMap<City, CityDto>().ReverseMap();
- CreateMap<UserDto, CompanyUserDto>();
- CreateMap<CompanyUserDto, UserDto>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap();
- CreateMap<CompanyUserDto, UserUpdateDto>().ReverseMap();
- CreateMap<CompanyUserDto, ApplicationUser>()
- .ForMember(m => m.UserRoles, op => op.Ignore())
- .ForMember(m => m.Id, op => op.Ignore());
- CreateMap<CompanyUserDto, ApplicationUser>().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email));
- CreateMap<ApplicationUser, CompanyUserDto>().ForMember(m => m.Password, op => op.Ignore());
- CreateMap<UserTaskStatus, UserTaskStatusDto>().ReverseMap();
- CreateMap<ChatMessageDto, ChatMessage>().ReverseMap();
-
- //-----------Contract----
- CreateMap<Contract, ContractDto>();
- CreateMap<ContractDto, Contract>()
- .ForMember(d => d.CreateDate, o => o.Ignore())
- .ForMember(d => d.CreateUser, o => o.Ignore());
- CreateMap<ContractAllowance, ContractAllowanceDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- CreateMap<ContractTask, ContractTaskDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- CreateMap<ContractWorkingDay, ContractWorkingDayDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- CreateMap<ContractTaskAttachment, ContractTaskAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- CreateMap<ProjectStage, ProjectStageDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- CreateMap<ProjectStageAttachment, ProjectStageAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
- }
- }
- }
|