243 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			243 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Marco.Pms.Model.Directory;
 | 
						|
using Marco.Pms.Model.Dtos.Directory;
 | 
						|
using Marco.Pms.Model.Dtos.Master;
 | 
						|
using Marco.Pms.Model.ViewModels.Directory;
 | 
						|
using Marco.Pms.Model.ViewModels.Master;
 | 
						|
 | 
						|
namespace Marco.Pms.Model.Mapper
 | 
						|
{
 | 
						|
    public static class DirectoryMapper
 | 
						|
    {
 | 
						|
        public static Contact ToContactFromCreateContactDto(this CreateContactDto createContactDto, Guid tenantId, Guid employeeId)
 | 
						|
        {
 | 
						|
 | 
						|
            return new Contact
 | 
						|
            {
 | 
						|
                Name = createContactDto.Name ?? string.Empty,
 | 
						|
                ContactCategoryId = createContactDto.ContactCategoryId,
 | 
						|
                Description = createContactDto.Description ?? string.Empty,
 | 
						|
                Organization = createContactDto?.Organization ?? string.Empty,
 | 
						|
                Address = createContactDto != null ? createContactDto.Address : string.Empty,
 | 
						|
                CreatedById = employeeId,
 | 
						|
                CreatedAt = DateTime.UtcNow,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static Contact ToContactFromUpdateContactDto(this UpdateContactDto updateContactDto, Guid tenantId, Contact contact)
 | 
						|
        {
 | 
						|
 | 
						|
            return new Contact
 | 
						|
            {
 | 
						|
                Id = updateContactDto.Id,
 | 
						|
                Name = updateContactDto.Name ?? string.Empty,
 | 
						|
                ContactCategoryId = updateContactDto.ContactCategoryId,
 | 
						|
                CreatedAt = contact.CreatedAt,
 | 
						|
                CreatedById = contact.CreatedById,
 | 
						|
                Description = updateContactDto.Description ?? string.Empty,
 | 
						|
                Organization = updateContactDto?.Organization ?? string.Empty,
 | 
						|
                Address = updateContactDto != null ? updateContactDto.Address : string.Empty,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactVM ToContactVMFromContact(this Contact contact)
 | 
						|
        {
 | 
						|
            return new ContactVM
 | 
						|
            {
 | 
						|
                Id = contact.Id,
 | 
						|
                Name = contact.Name,
 | 
						|
                ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null,
 | 
						|
                Description = contact.Description ?? string.Empty,
 | 
						|
                Organization = contact.Organization ?? string.Empty,
 | 
						|
                Address = contact.Address ?? string.Empty
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactProfileVM ToContactProfileVMFromContact(this Contact contact)
 | 
						|
        {
 | 
						|
            return new ContactProfileVM
 | 
						|
            {
 | 
						|
                Id = contact.Id,
 | 
						|
                Name = contact.Name,
 | 
						|
                ContactCategory = contact.ContactCategory != null ? contact.ContactCategory.ToContactCategoryVMFromContactCategoryMaster() : null,
 | 
						|
                Description = contact.Description ?? string.Empty,
 | 
						|
                Organization = contact.Organization ?? string.Empty,
 | 
						|
                Address = contact.Address ?? string.Empty,
 | 
						|
                CreatedAt = contact.CreatedAt,
 | 
						|
                CreatedBy = contact.CreatedBy != null ? contact.CreatedBy.ToBasicEmployeeVMFromEmployee() : null
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        //Contact Phone Mapper
 | 
						|
        public static ContactPhone ToContactPhoneFromCreateContactPhoneDto(this CreateContactPhoneDto createContactPhoneDto, Guid tenantId, Guid contactId)
 | 
						|
        {
 | 
						|
            return new ContactPhone
 | 
						|
            {
 | 
						|
                Label = createContactPhoneDto.Label ?? string.Empty,
 | 
						|
                PhoneNumber = createContactPhoneDto.PhoneNumber ?? string.Empty,
 | 
						|
                ContactId = contactId,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactPhone ToContactPhoneFromUpdateContactPhoneDto(this UpdateContactPhoneDto updateContactPhoneDto, Guid tenantId, Guid contactId)
 | 
						|
        {
 | 
						|
            return new ContactPhone
 | 
						|
            {
 | 
						|
                Id = updateContactPhoneDto.Id ?? Guid.Empty,
 | 
						|
                Label = updateContactPhoneDto.Label ?? string.Empty,
 | 
						|
                PhoneNumber = updateContactPhoneDto.PhoneNumber ?? string.Empty,
 | 
						|
                ContactId = contactId,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactPhoneVM ToContactPhoneVMFromContactPhone(this ContactPhone phone)
 | 
						|
        {
 | 
						|
            return new ContactPhoneVM
 | 
						|
            {
 | 
						|
                Id = phone.Id,
 | 
						|
                Label = phone.Label ?? string.Empty,
 | 
						|
                PhoneNumber = phone.PhoneNumber ?? string.Empty,
 | 
						|
                ContactId = phone.ContactId
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        //Contact Email Mapper
 | 
						|
        public static ContactEmail ToContactEmailFromCreateContactEmailDto(this CreateContactEmailDto createContactEmailDto, Guid tenantId, Guid contactId)
 | 
						|
        {
 | 
						|
            return new ContactEmail
 | 
						|
            {
 | 
						|
                Label = createContactEmailDto.Label ?? string.Empty,
 | 
						|
                EmailAddress = createContactEmailDto.EmailAddress ?? string.Empty,
 | 
						|
                ContactId = contactId,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactEmail ToContactEmailFromUpdateContactEmailDto(this UpdateContactEmailDto updateContactEmailDto, Guid tenantId, Guid contactId)
 | 
						|
        {
 | 
						|
            return new ContactEmail
 | 
						|
            {
 | 
						|
                Id = updateContactEmailDto.Id ?? Guid.Empty,
 | 
						|
                Label = updateContactEmailDto.Label ?? string.Empty,
 | 
						|
                EmailAddress = updateContactEmailDto.EmailAddress ?? string.Empty,
 | 
						|
                ContactId = contactId,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactEmailVM ToContactEmailVMFromContactEmail(this ContactEmail email)
 | 
						|
        {
 | 
						|
            return new ContactEmailVM
 | 
						|
            {
 | 
						|
                Id = email.Id,
 | 
						|
                Label = email.Label ?? string.Empty,
 | 
						|
                EmailAddress = email.EmailAddress ?? string.Empty,
 | 
						|
                ContactId = email.ContactId
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        //Contact Tag Mapper
 | 
						|
        public static ContactTagMaster ToContactTagMasterFromCreateContactTagDto(this CreateContactTagDto createContactTagDto, Guid tenantId)
 | 
						|
        {
 | 
						|
            return new ContactTagMaster
 | 
						|
            {
 | 
						|
                Name = createContactTagDto.Name ?? string.Empty,
 | 
						|
                Description = createContactTagDto.Description ?? string.Empty,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactTagMaster ToContactTagMasterFromUpdateContactTagDto(this UpdateContactTagDto updateContactTagDto, Guid tenantId)
 | 
						|
        {
 | 
						|
            return new ContactTagMaster
 | 
						|
            {
 | 
						|
                Id = updateContactTagDto.Id,
 | 
						|
                Name = updateContactTagDto.Name ?? string.Empty,
 | 
						|
                Description = updateContactTagDto.Description ?? string.Empty,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactTagVM ToContactTagVMFromContactTagMaster(this ContactTagMaster contactTag)
 | 
						|
        {
 | 
						|
            return new ContactTagVM
 | 
						|
            {
 | 
						|
                Id = contactTag.Id,
 | 
						|
                Description = contactTag.Description ?? string.Empty,
 | 
						|
                Name = contactTag.Name ?? string.Empty,
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        //Contact Category Mapper
 | 
						|
        public static ContactCategoryMaster ToContactCategoryMasterFromCreateContactCategoryDto(this CreateContactCategoryDto createContactTypeDto, Guid tenantId)
 | 
						|
        {
 | 
						|
            return new ContactCategoryMaster
 | 
						|
            {
 | 
						|
                Name = createContactTypeDto.Name ?? string.Empty,
 | 
						|
                Description = createContactTypeDto.Description ?? string.Empty,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactCategoryMaster ToContactCategoryMasterFromUpdateContactCategoryDto(this UpdateContactCategoryDto updateContactTypeDto, Guid tenantId)
 | 
						|
        {
 | 
						|
            return new ContactCategoryMaster
 | 
						|
            {
 | 
						|
                Id = updateContactTypeDto.Id,
 | 
						|
                Name = updateContactTypeDto.Name ?? string.Empty,
 | 
						|
                Description = updateContactTypeDto.Description ?? string.Empty,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactCategoryVM ToContactCategoryVMFromContactCategoryMaster(this ContactCategoryMaster contactType)
 | 
						|
        {
 | 
						|
            return new ContactCategoryVM
 | 
						|
            {
 | 
						|
                Id = contactType.Id,
 | 
						|
                Name = contactType.Name ?? string.Empty,
 | 
						|
                Description = contactType.Description ?? string.Empty,
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        // Bucket
 | 
						|
        public static BucketVM ToBucketVMFromBucket(this Bucket bucket)
 | 
						|
        {
 | 
						|
            return new BucketVM
 | 
						|
            {
 | 
						|
                Id = bucket.Id,
 | 
						|
                Name = bucket.Name,
 | 
						|
                Description = bucket.Description,
 | 
						|
                CreatedBy = bucket.CreatedBy != null ? bucket.CreatedBy.ToBasicEmployeeVMFromEmployee() : null
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static AssignBucketVM ToAssignBucketVMFromBucket(this Bucket bucket)
 | 
						|
        {
 | 
						|
            return new AssignBucketVM
 | 
						|
            {
 | 
						|
                Id = bucket.Id,
 | 
						|
                Name = bucket.Name,
 | 
						|
                Description = bucket.Description,
 | 
						|
                CreatedBy = bucket.CreatedBy != null ? bucket.CreatedBy.ToBasicEmployeeVMFromEmployee() : null
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        //Contact Note
 | 
						|
        public static ContactNote ToContactNoteFromCreateContactNoteDto(this CreateContactNoteDto noteDto, Guid tenantId, Guid employeeId)
 | 
						|
        {
 | 
						|
            return new ContactNote
 | 
						|
            {
 | 
						|
                Note = noteDto.Note,
 | 
						|
                ContactId = noteDto.ContactId,
 | 
						|
                CreatedAt = DateTime.UtcNow,
 | 
						|
                CreatedById = employeeId,
 | 
						|
                TenantId = tenantId
 | 
						|
            };
 | 
						|
        }
 | 
						|
        public static ContactNoteVM ToContactNoteVMFromContactNote(this ContactNote note)
 | 
						|
        {
 | 
						|
            return new ContactNoteVM
 | 
						|
            {
 | 
						|
                Id = note.Id,
 | 
						|
                Note = note.Note,
 | 
						|
                ContactId = note.ContactId,
 | 
						|
                CreatedAt = note.CreatedAt,
 | 
						|
                CreatedBy = note.Createdby != null ? note.Createdby.ToBasicEmployeeVMFromEmployee() : null,
 | 
						|
                IsActive = note.IsActive
 | 
						|
            };
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |