Corrected the logic of updating images and add file size in details View model
This commit is contained in:
parent
49da601092
commit
9e7651f345
@ -10,5 +10,7 @@ namespace Marco.Pms.Model.ViewModels.PurchaseInvoice
|
|||||||
public string? ContentType { get; set; }
|
public string? ContentType { get; set; }
|
||||||
public string? PreSignedUrl { get; set; }
|
public string? PreSignedUrl { get; set; }
|
||||||
public string? ThumbPreSignedUrl { get; set; }
|
public string? ThumbPreSignedUrl { get; set; }
|
||||||
|
public long FileSize { get; set; }
|
||||||
|
public DateTime UploadedAt { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -765,22 +765,18 @@ namespace Marco.Pms.Services.Service
|
|||||||
.Where(iat => typeIds.Contains(iat.Id))
|
.Where(iat => typeIds.Contains(iat.Id))
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|
||||||
var invalidTypeIds = typeIds.Except(validTypes.Select(t => t.Id)).ToList();
|
|
||||||
if (invalidTypeIds.Any())
|
|
||||||
{
|
|
||||||
foreach (var invalidId in invalidTypeIds)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("UpdatePurchaseInvoiceAsync failed: Invalid attachment type ID {AttachmentTypeId}.", invalidId);
|
|
||||||
}
|
|
||||||
return ApiResponse<object>.ErrorResponse("Invalid attachment types", $"One or more attachment types are invalid: {string.Join(", ", invalidTypeIds)}", 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
var preparedDocuments = new List<Document>();
|
var preparedDocuments = new List<Document>();
|
||||||
var preparedAttachments = new List<PurchaseInvoiceAttachment>();
|
var preparedAttachments = new List<PurchaseInvoiceAttachment>();
|
||||||
|
|
||||||
// Process each new attachment.
|
// Process each new attachment.
|
||||||
foreach (var attachment in newAttachments)
|
foreach (var attachment in newAttachments)
|
||||||
{
|
{
|
||||||
|
var attachmentType = validTypes.FirstOrDefault(t => t.Id == attachment.InvoiceAttachmentTypeId);
|
||||||
|
if (attachmentType == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("UpdatePurchaseInvoiceAsync failed: Invalid attachment type ID {AttachmentTypeId}.", attachment.InvoiceAttachmentTypeId);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Invalid attachment types", $"One or more attachment types are invalid: {attachment.InvoiceAttachmentTypeId}", 400);
|
||||||
|
}
|
||||||
// Validate base64 data presence.
|
// Validate base64 data presence.
|
||||||
var base64Data = attachment.Base64Data?.Split(',').LastOrDefault();
|
var base64Data = attachment.Base64Data?.Split(',').LastOrDefault();
|
||||||
if (string.IsNullOrWhiteSpace(base64Data))
|
if (string.IsNullOrWhiteSpace(base64Data))
|
||||||
@ -820,7 +816,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
preparedAttachments.Add(new PurchaseInvoiceAttachment
|
preparedAttachments.Add(new PurchaseInvoiceAttachment
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
InvoiceAttachmentTypeId = attachment.InvoiceAttachmentTypeId,
|
InvoiceAttachmentTypeId = attachmentType.Id,
|
||||||
PurchaseInvoiceId = id,
|
PurchaseInvoiceId = id,
|
||||||
DocumentId = documentId,
|
DocumentId = documentId,
|
||||||
UploadedAt = DateTime.UtcNow,
|
UploadedAt = DateTime.UtcNow,
|
||||||
@ -857,7 +853,10 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
_logger.LogInfo("Purchase invoice updated successfully. InvoiceId: {InvoiceId}, TenantId: {TenantId}, UpdatedById: {UserId}", id, tenantId, loggedInEmployee.Id);
|
_logger.LogInfo("Purchase invoice updated successfully. InvoiceId: {InvoiceId}, TenantId: {TenantId}, UpdatedById: {UserId}", id, tenantId, loggedInEmployee.Id);
|
||||||
|
|
||||||
return ApiResponse<object>.SuccessResponse(model, "Purchase invoice updated successfully.", 200);
|
var response = _mapper.Map<PurchaseInvoiceListVM>(purchaseInvoice);
|
||||||
|
response.Project = projectVm;
|
||||||
|
|
||||||
|
return ApiResponse<object>.SuccessResponse(response, "Purchase invoice updated successfully.", 200);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user