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() .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().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() .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() .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().ForMember(m => m.Password, op => op.Ignore()); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap() .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, UserRoleDto>().ReverseMap(); CreateMap() .ForMember(m => m.RoleId, op => op.MapFrom(mp => mp.Id)) .ForMember(m => m.RoleName, op => op.MapFrom(mp => mp.Name)) .ReverseMap(); //identity role CreateMap() .ForMember(m => m.Id, op => op.Ignore()) .ForMember(m => m.RolePermissions, op => op.Ignore()) ; CreateMap(); CreateMap().ReverseMap(); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()).ReverseMap(); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap(); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap(); CreateMap() .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().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap(); CreateMap() .ForMember(s => s.TeamUserCount, o => o.MapFrom(s => s.TeamUsers == null ? 0 : s.TeamUsers.Count)); CreateMap() .ForMember(s => s.ProjectTeamIds, o => o.MapFrom(s => s.ProjectTeams != null ? s.ProjectTeams.Select(u => u.TeamId).ToList() : new List())); CreateMap(); CreateMap() .ForMember(d => d.CreateDate, o => o.Ignore()) .ForMember(d => d.CreateUser, o => o.Ignore()); CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().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().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); CreateMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap(); CreateMap().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)).ReverseMap(); CreateMap().ReverseMap(); CreateMap() .ForMember(m => m.UserRoles, op => op.Ignore()) .ForMember(m => m.Id, op => op.Ignore()); CreateMap().ForMember(m => m.UserName, o => o.MapFrom(s => s.Email)); CreateMap().ForMember(m => m.Password, op => op.Ignore()); CreateMap().ReverseMap(); //-----------Contract---- CreateMap(); CreateMap() .ForMember(d => d.CreateDate, o => o.Ignore()) .ForMember(d => d.CreateUser, o => o.Ignore()); CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ; CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ; CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ; CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ; CreateMap().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ; } } }