shoc-backend/Api.SeaHavenIndustries/DTOs/Workorder_DTO.cs
Arthur Bassi 1edcf479ae fix(work-orders): apply account scope across create and reads [SH-221]
Stamp WorkOrder.AccountId on all create paths and filter board/list/search/detail by server-derived account claims so scoped callers cannot cross accounts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-11 10:45:37 -03:00

116 lines
No EOL
5.4 KiB
C#

using Data.SeaHavenIndustries;
using Data.SeaHavenIndustries.Enums;
namespace Api.SeaHavenIndustries.DTOs
{
public class Workorder_DTO
{
public string? WorkerOrderNumber { get; set; }
public string? WorkerOrderTitle { get; set; }
public string? Description { get; set; }
public string? PO { get; set; }
public string? TT { get; set; }
public string? AssignTo { get; set; }
public DateTime? DueDate { get; set; }
public WorkOrderPriority? Priority { get; set; }
public int? LocationId { get; set; }
public bool? istemplate { get; set; }
public List<IFormFile>? Attachments { get; set; }
public string? BeforPhotoIssue { get; set; }
public IFormFile? BeforPhotoAttachment { get; set; }
public string? AfterPhotoIssue { get; set; }
public IFormFile? AfterPhotoAttachment { get; set; }
public string? SignOffName { get; set; }
public IFormFile? SignOffAttachment { get; set; }
public string? SignOffSignature { get; set; }
public List<int>? ContactIds { get; set; }
public List<int>? CategoryIds { get; set; }
public string? Customer { get; set; }
public static WorkOrder MapToEntity(Workorder_DTO dto, string userId)
{
if (dto == null) return null!;
return new WorkOrder
{
WorkerOrderNumber = dto.WorkerOrderNumber,
WorkerOrderTitle = dto.WorkerOrderTitle,
Description = dto.Description,
PO = dto.PO,
TT = dto.TT,
AssignTo = dto.AssignTo,
DueDate = dto.DueDate,
Priority = (dto.Priority ?? WorkOrderPriority.Medium).ToString(),
LocationId = dto.LocationId,
istemplate = dto.istemplate ?? false,
Status = WorkOrderStatus.Open.ToString(),
BeforPhotoIssue = dto.BeforPhotoIssue,
AfterPhotoIssue = dto.AfterPhotoIssue,
SignOffName = dto.SignOffName,
SignOffSignature = dto.SignOffSignature,
createdby = userId,
CreatedDate = DateTime.UtcNow
};
}
}
public class EditWorkorder_DTO
{
public int? Id { get; set; }
public string? WorkerOrderNumber { get; set; }
public string? WorkerOrderTitle { get; set; }
public string? Description { get; set; }
public string? PO { get; set; }
public string? TT { get; set; }
public string? AssignTo { get; set; }
public DateTime? DueDate { get; set; }
public WorkOrderPriority? Priority { get; set; }
public WorkOrderStatus? Status { get; set; }
public int? LocationId { get; set; }
public string? Problem { get; set; }
public string? Trade { get; set; }
public string? SubTrade { get; set; }
public decimal? VendorNTE { get; set; }
public DateTime? ScheduledDate { get; set; }
public DateTime? CompletedDate { get; set; }
public string? Source { get; set; }
public List<IFormFile>? Attachments { get; set; }
public string? BeforPhotoIssue { get; set; }
public IFormFile? BeforPhotoAttachment { get; set; }
public string? AfterPhotoIssue { get; set; }
public IFormFile? AfterPhotoAttachment { get; set; }
public string? SignOffName { get; set; }
public IFormFile? SignOffAttachment { get; set; }
public string? SignOffSignature { get; set; }
public List<int>? ContactIds { get; set; }
public List<int>? CategoryIds { get; set; }
public static void UpdateEntity(EditWorkorder_DTO dto, WorkOrder entity)
{
if (dto == null || entity == null) return;
if (dto.WorkerOrderNumber != null) entity.WorkerOrderNumber = dto.WorkerOrderNumber;
if (dto.WorkerOrderTitle != null) entity.WorkerOrderTitle = dto.WorkerOrderTitle;
if (dto.Description != null) entity.Description = dto.Description;
if (dto.PO != null) entity.PO = dto.PO;
if (dto.TT != null) entity.TT = dto.TT;
if (dto.AssignTo != null) entity.AssignTo = dto.AssignTo;
if (dto.DueDate.HasValue) entity.DueDate = dto.DueDate;
if (dto.Priority.HasValue) entity.Priority = dto.Priority.ToString()!;
if (dto.Status.HasValue) entity.Status = dto.Status.ToString()!;
if (dto.LocationId.HasValue) entity.LocationId = dto.LocationId;
if (dto.Problem != null) entity.Problem = dto.Problem;
if (dto.Trade != null) entity.Trade = dto.Trade;
if (dto.SubTrade != null) entity.SubTrade = dto.SubTrade;
if (dto.VendorNTE.HasValue) entity.VendorNTE = dto.VendorNTE;
if (dto.ScheduledDate.HasValue) entity.ScheduledDate = dto.ScheduledDate;
if (dto.CompletedDate.HasValue) entity.CompletedDate = dto.CompletedDate;
if (dto.Source != null) entity.Source = dto.Source;
if (dto.BeforPhotoIssue != null) entity.BeforPhotoIssue = dto.BeforPhotoIssue;
if (dto.AfterPhotoIssue != null) entity.AfterPhotoIssue = dto.AfterPhotoIssue;
if (dto.SignOffName != null) entity.SignOffName = dto.SignOffName;
if (dto.SignOffSignature != null) entity.SignOffSignature = dto.SignOffSignature;
entity.LastModificationTime = DateTime.UtcNow;
}
}
}