Corrected the logic of updating images and add file size in details View model

This commit is contained in:
ashutosh.nehete 2025-12-01 09:49:41 +05:30
parent 49da601092
commit 9e7651f345
2 changed files with 13 additions and 12 deletions

View File

@ -10,5 +10,7 @@ namespace Marco.Pms.Model.ViewModels.PurchaseInvoice
public string? ContentType { get; set; }
public string? PreSignedUrl { get; set; }
public string? ThumbPreSignedUrl { get; set; }
public long FileSize { get; set; }
public DateTime UploadedAt { get; set; }
}
}

View File

@ -765,22 +765,18 @@ namespace Marco.Pms.Services.Service
.Where(iat => typeIds.Contains(iat.Id))
.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 preparedAttachments = new List<PurchaseInvoiceAttachment>();
// Process each new attachment.
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.
var base64Data = attachment.Base64Data?.Split(',').LastOrDefault();
if (string.IsNullOrWhiteSpace(base64Data))
@ -820,7 +816,7 @@ namespace Marco.Pms.Services.Service
preparedAttachments.Add(new PurchaseInvoiceAttachment
{
Id = Guid.NewGuid(),
InvoiceAttachmentTypeId = attachment.InvoiceAttachmentTypeId,
InvoiceAttachmentTypeId = attachmentType.Id,
PurchaseInvoiceId = id,
DocumentId = documentId,
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);
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)
{