Document_Manager #129
@ -327,6 +327,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
/// Uploads a document attachment for an Employee or Project.
|
||||
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
||||
/// </summary>
|
||||
|
||||
[HttpPost("upload")]
|
||||
public async Task<IActionResult> UploadDocumentAsync([FromBody] DocumentAttachmentDto model)
|
||||
{
|
||||
@ -535,6 +536,17 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("verify/{id}")]
|
||||
public async Task<IActionResult> VerifyDocumentAsync(Guid id)
|
||||
{
|
||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
using var scope = _serviceScope.CreateScope();
|
||||
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Document is verified successfully", 200));
|
||||
}
|
||||
|
||||
[HttpPut("edit/{id}")]
|
||||
public async Task<IActionResult> UpdateDocumentAsync(Guid id, [FromBody] UpdateDocumentAttachmentDto model)
|
||||
{
|
||||
@ -696,53 +708,68 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
dbContext.Documents.Add(document);
|
||||
|
||||
// Record new document attachment as the current version
|
||||
var attachment = new DocumentAttachment
|
||||
if (oldAttachment.IsVerified == true)
|
||||
{
|
||||
Name = model.Name,
|
||||
DocumentId = model.DocumentId,
|
||||
Description = model.Description,
|
||||
IsCurrentVersion = true,
|
||||
EntityId = oldAttachment.EntityId,
|
||||
DocumentDataId = document.Id,
|
||||
UploadedAt = DateTime.UtcNow,
|
||||
UploadedById = loggedInEmployee.Id,
|
||||
DocumentTypeId = oldAttachment.DocumentTypeId,
|
||||
TenantId = oldAttachment.TenantId
|
||||
};
|
||||
|
||||
dbContext.DocumentAttachments.Add(attachment);
|
||||
|
||||
// Mark old version as not current
|
||||
oldAttachment.IsCurrentVersion = false;
|
||||
|
||||
// Version mapping
|
||||
AttachmentVersionMapping versionMapping;
|
||||
if (oldVersionMapping != null)
|
||||
{
|
||||
versionMapping = new AttachmentVersionMapping
|
||||
// Record new document attachment as the current version
|
||||
var attachment = new DocumentAttachment
|
||||
{
|
||||
ParentAttachmentId = oldVersionMapping.ParentAttachmentId,
|
||||
ChildAttachmentId = attachment.Id,
|
||||
Version = (oldVersionMapping.Version + 1),
|
||||
TenantId = tenantId
|
||||
Name = model.Name,
|
||||
DocumentId = model.DocumentId,
|
||||
Description = model.Description,
|
||||
IsCurrentVersion = true,
|
||||
EntityId = oldAttachment.EntityId,
|
||||
DocumentDataId = document.Id,
|
||||
UploadedAt = DateTime.UtcNow,
|
||||
UploadedById = loggedInEmployee.Id,
|
||||
DocumentTypeId = oldAttachment.DocumentTypeId,
|
||||
TenantId = oldAttachment.TenantId
|
||||
};
|
||||
|
||||
dbContext.DocumentAttachments.Add(attachment);
|
||||
|
||||
// Mark old version as not current
|
||||
oldAttachment.IsCurrentVersion = false;
|
||||
|
||||
// Version mapping
|
||||
AttachmentVersionMapping versionMapping;
|
||||
if (oldVersionMapping != null)
|
||||
{
|
||||
versionMapping = new AttachmentVersionMapping
|
||||
{
|
||||
ParentAttachmentId = oldVersionMapping.ParentAttachmentId,
|
||||
ChildAttachmentId = attachment.Id,
|
||||
Version = (oldVersionMapping.Version + 1),
|
||||
TenantId = tenantId
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
versionMapping = new AttachmentVersionMapping
|
||||
{
|
||||
ParentAttachmentId = attachment.Id,
|
||||
ChildAttachmentId = attachment.Id,
|
||||
Version = 1,
|
||||
TenantId = tenantId
|
||||
};
|
||||
}
|
||||
dbContext.AttachmentVersionMappings.Add(versionMapping);
|
||||
|
||||
newAttachment = attachment;
|
||||
newVersionMapping = versionMapping;
|
||||
_logger.LogInfo("Created new current version for AttachmentId: {AttachmentId}", attachment.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
versionMapping = new AttachmentVersionMapping
|
||||
{
|
||||
ParentAttachmentId = attachment.Id,
|
||||
ChildAttachmentId = attachment.Id,
|
||||
Version = 1,
|
||||
TenantId = tenantId
|
||||
};
|
||||
}
|
||||
dbContext.AttachmentVersionMappings.Add(versionMapping);
|
||||
oldAttachment.Name = model.Name;
|
||||
oldAttachment.DocumentId = model.DocumentId;
|
||||
oldAttachment.Description = model.Description;
|
||||
oldAttachment.DocumentDataId = document.Id;
|
||||
|
||||
newAttachment = oldAttachment;
|
||||
newVersionMapping = oldVersionMapping ?? new AttachmentVersionMapping();
|
||||
_logger.LogInfo("Attachment metadata updated for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||
}
|
||||
|
||||
newAttachment = attachment;
|
||||
newVersionMapping = versionMapping;
|
||||
_logger.LogInfo("Created new current version for AttachmentId: {AttachmentId}", attachment.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -752,7 +779,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
oldAttachment.Description = model.Description;
|
||||
if (oldAttachment.IsVerified == true)
|
||||
{
|
||||
oldAttachment.IsVerified = false;
|
||||
oldAttachment.IsVerified = null;
|
||||
_logger.LogInfo("Reset verification flag for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||
}
|
||||
oldAttachment.UpdatedAt = DateTime.UtcNow;
|
||||
|
Loading…
x
Reference in New Issue
Block a user