2026-05-06 10:49:33 -05:00
|
|
|
using Data.SeaHavenIndustries;
|
|
|
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
|
|
Add LocationController with full CRUD and extended model
- Extend Locations model with Address, City, State, ZipCode, Phone, Contact, ContactEmail, Status, AccountId
- Update Location DTOs to match new fields
- Create LocationController with paged list, get by ID, create, update, delete
- Support both REST-style routes (/api/Location/{id}) and legacy query routes (/api/Location/DeleteLocation?id=)
- Add migration for new Location columns
2026-04-16 17:09:59 -04:00
|
|
|
namespace Api.SeaHavenIndustries.DTOs
|
2024-09-28 14:58:36 -04:00
|
|
|
{
|
2026-09-14 21:44:45 -03:00
|
|
|
// SH-138: additive site-contact write row (id optional on writes)
|
|
|
|
|
public class SiteContactInput_DTO
|
|
|
|
|
{
|
|
|
|
|
public int? Id { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
|
|
|
|
public string? Phone { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-25 11:19:29 -03:00
|
|
|
/// <summary>Contacts and notes edited from the work-order Site dialog.</summary>
|
|
|
|
|
public class SiteContactInfoInput_DTO
|
|
|
|
|
{
|
|
|
|
|
public List<SiteContactInput_DTO>? Contacts { get; set; }
|
|
|
|
|
public string? Notes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 14:58:36 -04:00
|
|
|
public class Location_DTO
|
|
|
|
|
{
|
|
|
|
|
public string? Title { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
Add LocationController with full CRUD and extended model
- Extend Locations model with Address, City, State, ZipCode, Phone, Contact, ContactEmail, Status, AccountId
- Update Location DTOs to match new fields
- Create LocationController with paged list, get by ID, create, update, delete
- Support both REST-style routes (/api/Location/{id}) and legacy query routes (/api/Location/DeleteLocation?id=)
- Add migration for new Location columns
2026-04-16 17:09:59 -04:00
|
|
|
public string? Address { get; set; }
|
|
|
|
|
public string? City { get; set; }
|
|
|
|
|
public string? State { get; set; }
|
|
|
|
|
public string? ZipCode { get; set; }
|
|
|
|
|
public string? Phone { get; set; }
|
|
|
|
|
public string? Contact { get; set; }
|
|
|
|
|
public string? ContactEmail { get; set; }
|
|
|
|
|
public string? Status { get; set; }
|
2026-04-16 17:15:28 -04:00
|
|
|
public string? AccountId { get; set; }
|
2026-09-25 11:19:29 -03:00
|
|
|
public string? Notes { get; set; }
|
2026-09-14 21:44:45 -03:00
|
|
|
public List<SiteContactInput_DTO>? Contacts { get; set; }
|
2026-04-16 17:15:28 -04:00
|
|
|
|
2026-08-26 14:18:38 -03:00
|
|
|
public int? GetAccountId() => LocationAccountIdMapping.ParseOptional(AccountId);
|
2026-05-06 10:49:33 -05:00
|
|
|
|
|
|
|
|
// ✅ Map API DTO to Service DTO
|
|
|
|
|
public CreateLocationDTO ToServiceCreateDTO()
|
|
|
|
|
{
|
|
|
|
|
return new CreateLocationDTO
|
|
|
|
|
{
|
|
|
|
|
LocationName = this.Name ?? "",
|
|
|
|
|
Address = this.Address,
|
|
|
|
|
City = this.City,
|
|
|
|
|
State = this.State,
|
2026-08-26 10:00:02 -03:00
|
|
|
Zipcode = this.ZipCode
|
2026-05-06 10:49:33 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Map from Entity to DTO
|
|
|
|
|
public static Location_DTO MapToModel(Locations entity)
|
|
|
|
|
{
|
|
|
|
|
return new Location_DTO
|
|
|
|
|
{
|
|
|
|
|
Title = entity.Title,
|
|
|
|
|
Name = entity.Name,
|
|
|
|
|
Address = entity.Address1,
|
|
|
|
|
City = entity.City,
|
|
|
|
|
State = entity.State,
|
|
|
|
|
ZipCode = entity.Zip,
|
|
|
|
|
Phone = entity.PhoneNumber,
|
|
|
|
|
Contact = null, // Not in database schema
|
|
|
|
|
ContactEmail = entity.Email,
|
|
|
|
|
Status = entity.Status,
|
2026-08-26 09:12:48 -03:00
|
|
|
AccountId = entity.AccountId?.ToString()
|
2026-05-06 10:49:33 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Map from DTO to Entity
|
|
|
|
|
public static Locations MapToEntity(Location_DTO dto, Locations? existingEntity = null)
|
|
|
|
|
{
|
|
|
|
|
var entity = existingEntity ?? new Locations();
|
|
|
|
|
|
|
|
|
|
entity.Title = dto.Title;
|
|
|
|
|
entity.Name = dto.Name;
|
|
|
|
|
entity.Address1 = dto.Address;
|
|
|
|
|
entity.City = dto.City;
|
|
|
|
|
entity.State = dto.State;
|
|
|
|
|
entity.Zip = dto.ZipCode;
|
|
|
|
|
entity.PhoneNumber = dto.Phone;
|
|
|
|
|
// Contact field doesn't exist in database schema - ignored
|
|
|
|
|
entity.Email = dto.ContactEmail;
|
|
|
|
|
entity.Status = dto.Status;
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DTO for list views
|
|
|
|
|
public class LocationListItem_DTO
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
|
|
|
|
public string? Title { get; set; }
|
|
|
|
|
|
|
|
|
|
// Map from Entity
|
|
|
|
|
public static LocationListItem_DTO MapToModel(Locations entity)
|
|
|
|
|
{
|
|
|
|
|
return new LocationListItem_DTO
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id,
|
|
|
|
|
Name = entity.Name,
|
|
|
|
|
Title = entity.Title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ✅ Map from Service DTO (no logic in controller)
|
|
|
|
|
public static LocationListItem_DTO FromServiceDTO(LocationDTO serviceDto)
|
|
|
|
|
{
|
|
|
|
|
return new LocationListItem_DTO
|
|
|
|
|
{
|
|
|
|
|
Id = serviceDto.Id,
|
|
|
|
|
Name = serviceDto.Name ?? serviceDto.Title,
|
|
|
|
|
Title = serviceDto.Title ?? serviceDto.Name
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ✅ Map collection from Service DTOs
|
|
|
|
|
public static IEnumerable<LocationListItem_DTO> FromServiceDTOs(IEnumerable<LocationDTO> serviceDtos)
|
|
|
|
|
{
|
|
|
|
|
return serviceDtos.Select(FromServiceDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DTO for location dropdown/simple view
|
|
|
|
|
public class LocationViewModel_DTO
|
|
|
|
|
{
|
|
|
|
|
public int? Id { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
|
|
|
|
|
|
|
|
|
// ✅ Map from Service DTO
|
|
|
|
|
public static LocationViewModel_DTO FromServiceDTO(LocationDTO serviceDto)
|
|
|
|
|
{
|
|
|
|
|
return new LocationViewModel_DTO
|
|
|
|
|
{
|
|
|
|
|
Id = serviceDto.Id,
|
|
|
|
|
Name = serviceDto.Name ?? serviceDto.Title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ✅ Map collection from Service DTOs
|
|
|
|
|
public static IEnumerable<LocationViewModel_DTO> FromServiceDTOs(IEnumerable<LocationDTO> serviceDtos)
|
|
|
|
|
{
|
|
|
|
|
return serviceDtos.Select(FromServiceDTO);
|
|
|
|
|
}
|
2024-09-28 14:58:36 -04:00
|
|
|
}
|
|
|
|
|
}
|