mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
129 lines
5 KiB
C#
129 lines
5 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Data.SeaHavenIndustries.Enums;
|
|
|
|
namespace SeaHaven.Services.DTOs
|
|
{
|
|
public class WorkOrderDTO
|
|
{
|
|
public int Id { get; set; }
|
|
public string? InternalWONumber { get; set; }
|
|
public string? WorkerOrderTitle { get; set; }
|
|
public string? Description { get; set; }
|
|
public WorkOrderStatus Status { get; set; }
|
|
public WorkOrderPriority Priority { get; set; }
|
|
public int? LocationId { get; set; }
|
|
public string? LocationName { get; set; }
|
|
public string? AssignTo { get; set; }
|
|
public DateTime? DueDate { get; set; }
|
|
public DateTime? CompletedDate { get; set; }
|
|
public DateTime? CreatedDate { get; set; }
|
|
public string? CreatedBy { get; set; }
|
|
public DateTime? ModifiedDate { get; set; }
|
|
public string? ModifiedBy { get; set; }
|
|
|
|
/// <summary>
|
|
/// Maps entity to DTO (Entity -> DTO)
|
|
/// </summary>
|
|
public static WorkOrderDTO MapToModel(WorkOrder entity)
|
|
{
|
|
if (entity == null) return null;
|
|
|
|
return new WorkOrderDTO
|
|
{
|
|
Id = entity.Id,
|
|
InternalWONumber = entity.InternalWONumber,
|
|
WorkerOrderTitle = entity.WorkerOrderTitle,
|
|
Description = entity.Description,
|
|
Status = Enum.TryParse<WorkOrderStatus>(entity.Status, out var status) ? status : WorkOrderStatus.Open,
|
|
Priority = Enum.TryParse<WorkOrderPriority>(entity.Priority, out var priority) ? priority : WorkOrderPriority.Medium,
|
|
LocationId = entity.LocationId,
|
|
LocationName = null,
|
|
AssignTo = entity.AssignTo,
|
|
DueDate = entity.DueDate,
|
|
CompletedDate = entity.CompletedDate,
|
|
CreatedDate = entity.CreatedDate,
|
|
CreatedBy = entity.createdby,
|
|
ModifiedDate = entity.LastModificationTime,
|
|
ModifiedBy = entity.LastModifierUserId?.ToString()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps DTO to entity (DTO -> Entity)
|
|
/// </summary>
|
|
public static WorkOrder MapToEntity(WorkOrderDTO dto)
|
|
{
|
|
if (dto == null) return null;
|
|
|
|
return new WorkOrder
|
|
{
|
|
Id = dto.Id,
|
|
InternalWONumber = dto.InternalWONumber,
|
|
WorkerOrderTitle = dto.WorkerOrderTitle,
|
|
Description = dto.Description,
|
|
Status = dto.Status.ToString(),
|
|
Priority = dto.Priority.ToString(),
|
|
LocationId = dto.LocationId,
|
|
AssignTo = dto.AssignTo,
|
|
DueDate = dto.DueDate,
|
|
CompletedDate = dto.CompletedDate
|
|
};
|
|
}
|
|
}
|
|
|
|
public class CreateWorkOrderDTO
|
|
{
|
|
public required string WorkerOrderTitle { get; set; }
|
|
public string? Description { get; set; }
|
|
public WorkOrderStatus? Status { get; set; }
|
|
public WorkOrderPriority? Priority { get; set; }
|
|
public int? LocationId { get; set; }
|
|
public string? AssignTo { get; set; }
|
|
public DateTime? DueDate { get; set; }
|
|
|
|
public static WorkOrder MapToEntity(CreateWorkOrderDTO dto)
|
|
{
|
|
if (dto == null) return null!;
|
|
|
|
return new WorkOrder
|
|
{
|
|
WorkerOrderTitle = dto.WorkerOrderTitle,
|
|
Description = dto.Description,
|
|
Status = (dto.Status ?? WorkOrderStatus.Open).ToString(),
|
|
Priority = (dto.Priority ?? WorkOrderPriority.Medium).ToString(),
|
|
LocationId = dto.LocationId,
|
|
AssignTo = dto.AssignTo,
|
|
DueDate = dto.DueDate,
|
|
CreatedDate = DateTime.UtcNow
|
|
};
|
|
}
|
|
}
|
|
|
|
public class UpdateWorkOrderDTO
|
|
{
|
|
public string? WorkerOrderTitle { get; set; }
|
|
public string? Description { get; set; }
|
|
public WorkOrderStatus? Status { get; set; }
|
|
public WorkOrderPriority? Priority { get; set; }
|
|
public int? LocationId { get; set; }
|
|
public string? AssignTo { get; set; }
|
|
public DateTime? DueDate { get; set; }
|
|
public DateTime? CompletedDate { get; set; }
|
|
|
|
public static void UpdateEntity(UpdateWorkOrderDTO dto, WorkOrder entity)
|
|
{
|
|
if (dto == null || entity == null) return;
|
|
|
|
if (dto.WorkerOrderTitle != null) entity.WorkerOrderTitle = dto.WorkerOrderTitle;
|
|
if (dto.Description != null) entity.Description = dto.Description;
|
|
if (dto.Status.HasValue) entity.Status = dto.Status.ToString()!;
|
|
if (dto.Priority.HasValue) entity.Priority = dto.Priority.ToString()!;
|
|
if (dto.LocationId.HasValue) entity.LocationId = dto.LocationId;
|
|
if (dto.AssignTo != null) entity.AssignTo = dto.AssignTo;
|
|
if (dto.DueDate.HasValue) entity.DueDate = dto.DueDate;
|
|
if (dto.CompletedDate.HasValue) entity.CompletedDate = dto.CompletedDate;
|
|
|
|
entity.LastModificationTime = DateTime.UtcNow;
|
|
}
|
|
}
|
|
}
|