mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 07:13:12 +00:00
122 lines
4.2 KiB
C#
122 lines
4.2 KiB
C#
using Data.SeaHavenIndustries;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
namespace Api.SeaHavenIndustries.DTOs
|
|
{
|
|
public class Contact_DTO
|
|
{
|
|
public string? Title { get; set; }
|
|
public string? Owner { get; set; }
|
|
public string? FirstName { get; set; }
|
|
public string? MiddleName { get; set; }
|
|
public string? LastName { get; set; }
|
|
public string? ContactType { get; set; }
|
|
public string? PhoneNumber { get; set; }
|
|
public string? Email { get; set; }
|
|
public string? Address1 { get; set; }
|
|
public string? Address2 { get; set; }
|
|
public string? City { get; set; }
|
|
public string? State { get; set; }
|
|
public string? Zip { get; set; }
|
|
public string? FacebookUrl { get; set; }
|
|
public string? LinkedInUrl { get; set; }
|
|
public string? TwitterUrl { get; set; }
|
|
public int? LocationId { get; set; }
|
|
public int? AccountId { get; set; }
|
|
|
|
// ✅ Map API DTO to Service DTO
|
|
public CreateContactDTO ToServiceCreateDTO()
|
|
{
|
|
return new CreateContactDTO
|
|
{
|
|
FirstName = this.FirstName,
|
|
LastName = this.LastName,
|
|
Email = this.Email ?? "",
|
|
Phone = this.PhoneNumber,
|
|
Title = this.Title,
|
|
Type = this.ContactType,
|
|
AccountId = this.AccountId
|
|
};
|
|
}
|
|
|
|
// Map from Entity to DTO (Model)
|
|
public static Contact_DTO MapToModel(Contacts entity)
|
|
{
|
|
return new Contact_DTO
|
|
{
|
|
Title = entity.Title,
|
|
Owner = entity.Owner,
|
|
FirstName = entity.FirstName,
|
|
MiddleName = entity.MiddleName,
|
|
LastName = entity.LastName,
|
|
ContactType = entity.ContactType,
|
|
PhoneNumber = entity.PhoneNumber,
|
|
Email = entity.Email,
|
|
Address1 = entity.Address1,
|
|
Address2 = entity.Address2,
|
|
City = entity.City,
|
|
State = entity.State,
|
|
Zip = entity.Zip,
|
|
FacebookUrl = entity.FacebookUrl,
|
|
LinkedInUrl = entity.LinkedInUrl,
|
|
TwitterUrl = entity.TwitterUrl,
|
|
LocationId = entity.LocationId,
|
|
AccountId = entity.AccountId
|
|
};
|
|
}
|
|
|
|
// Map from DTO (Model) to Entity
|
|
public static Contacts MapToEntity(Contact_DTO dto, Contacts? existingEntity = null)
|
|
{
|
|
var entity = existingEntity ?? new Contacts();
|
|
|
|
entity.Title = dto.Title;
|
|
entity.Owner = dto.Owner;
|
|
entity.FirstName = dto.FirstName;
|
|
entity.MiddleName = dto.MiddleName;
|
|
entity.LastName = dto.LastName;
|
|
entity.ContactType = dto.ContactType;
|
|
entity.PhoneNumber = dto.PhoneNumber;
|
|
entity.Email = dto.Email;
|
|
entity.Address1 = dto.Address1;
|
|
entity.Address2 = dto.Address2;
|
|
entity.City = dto.City;
|
|
entity.State = dto.State;
|
|
entity.Zip = dto.Zip;
|
|
entity.FacebookUrl = dto.FacebookUrl;
|
|
entity.LinkedInUrl = dto.LinkedInUrl;
|
|
entity.TwitterUrl = dto.TwitterUrl;
|
|
entity.LocationId = dto.LocationId;
|
|
entity.AccountId = dto.AccountId;
|
|
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
// DTO for contact list view
|
|
public class ContactListItem_DTO
|
|
{
|
|
public int Id { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? Email { get; set; }
|
|
public string? Phone { get; set; }
|
|
|
|
// ✅ Map from Service DTO
|
|
public static ContactListItem_DTO FromServiceDTO(ContactDTO serviceDto)
|
|
{
|
|
return new ContactListItem_DTO
|
|
{
|
|
Id = serviceDto.Id,
|
|
Name = (serviceDto.FirstName + " " + serviceDto.LastName).Trim(),
|
|
Email = serviceDto.Email,
|
|
Phone = serviceDto.Phone
|
|
};
|
|
}
|
|
|
|
// ✅ Map collection from Service DTOs
|
|
public static IEnumerable<ContactListItem_DTO> FromServiceDTOs(IEnumerable<ContactDTO> serviceDtos)
|
|
{
|
|
return serviceDtos.Select(FromServiceDTO);
|
|
}
|
|
}
|
|
}
|