111 lines
4.2 KiB
C#

using AutoMapper;
using Marco.Pms.Model.Directory;
using Marco.Pms.Model.Dtos.Directory;
using Marco.Pms.Model.Dtos.Project;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Master;
using Marco.Pms.Model.MongoDBModels;
using Marco.Pms.Model.Projects;
using Marco.Pms.Model.ViewModels.Activities;
using Marco.Pms.Model.ViewModels.Directory;
using Marco.Pms.Model.ViewModels.Employee;
using Marco.Pms.Model.ViewModels.Master;
using Marco.Pms.Model.ViewModels.Projects;
namespace Marco.Pms.Services.MappingProfiles
{
public class MappingProfile : Profile
{
public MappingProfile()
{
#region ======================================================= Projects =======================================================
// Your mappings
CreateMap<Project, ProjectVM>();
CreateMap<Project, ProjectInfoVM>();
CreateMap<ProjectMongoDB, ProjectInfoVM>();
CreateMap<UpdateProjectDto, Project>();
CreateMap<Project, ProjectListVM>();
CreateMap<Project, ProjectDto>();
CreateMap<ProjectMongoDB, ProjectListVM>();
CreateMap<ProjectMongoDB, ProjectVM>()
.ForMember(
dest => dest.Id,
// Explicitly and safely convert string Id to Guid Id
opt => opt.MapFrom(src => new Guid(src.Id))
);
CreateMap<ProjectMongoDB, Project>()
.ForMember(
dest => dest.Id,
// Explicitly and safely convert string Id to Guid Id
opt => opt.MapFrom(src => new Guid(src.Id))
).ForMember(
dest => dest.ProjectStatusId,
// Explicitly and safely convert string ProjectStatusId to Guid ProjectStatusId
opt => opt.MapFrom(src => src.ProjectStatus == null ? Guid.Empty : new Guid(src.ProjectStatus.Id))
);
CreateMap<StatusMasterMongoDB, StatusMaster>();
CreateMap<ProjectVM, Project>();
CreateMap<CreateProjectDto, Project>();
CreateMap<ProjectAllocationDot, ProjectAllocation>()
.ForMember(
dest => dest.EmployeeId,
// Explicitly and safely convert string ProjectStatusId to Guid ProjectStatusId
opt => opt.MapFrom(src => src.EmpID));
CreateMap<ProjectsAllocationDto, ProjectAllocation>();
CreateMap<ProjectAllocation, ProjectAllocationVM>();
CreateMap<BuildingDto, Building>();
CreateMap<FloorDto, Floor>();
CreateMap<WorkAreaDto, WorkArea>();
CreateMap<WorkItemDto, WorkItem>()
.ForMember(
dest => dest.Description,
opt => opt.MapFrom(src => src.Comment));
#endregion
#region ======================================================= Employee =======================================================
CreateMap<Employee, EmployeeVM>();
CreateMap<Employee, BasicEmployeeVM>();
#endregion
#region ======================================================= Directory =======================================================
CreateMap<Contact, ContactVM>();
CreateMap<CreateContactDto, Contact>();
CreateMap<Contact, ContactProfileVM>();
CreateMap<ContactPhone, ContactPhoneVM>();
CreateMap<CreateContactPhoneDto, ContactPhone>();
CreateMap<ContactEmail, ContactEmailVM>();
CreateMap<CreateContactEmailDto, ContactEmail>();
CreateMap<ContactCategoryMaster, ContactCategoryVM>();
CreateMap<ContactTagMaster, ContactTagVM>();
CreateMap<Bucket, BucketVM>();
CreateMap<Bucket, AssignBucketVM>();
CreateMap<ContactNote, ContactNoteVM>()
.ForMember(
dest => dest.ContactName,
opt => opt.MapFrom(src => src.Contact != null ? src.Contact.Name : string.Empty)
)
.ForMember(
dest => dest.OrganizationName,
opt => opt.MapFrom(src => src.Contact != null ? src.Contact.Organization : string.Empty)
);
#endregion
}
}
}