From 9e7651f345f389f849ceee884c4bdf428887397d Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Mon, 1 Dec 2025 09:49:41 +0530 Subject: [PATCH] Corrected the logic of updating images and add file size in details View model --- .../PurchaseInvoiceAttachmentVM.cs | 2 ++ .../Service/PurchaseInvoiceService.cs | 23 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Marco.Pms.Model/ViewModels/PurchaseInvoice/PurchaseInvoiceAttachmentVM.cs b/Marco.Pms.Model/ViewModels/PurchaseInvoice/PurchaseInvoiceAttachmentVM.cs index 815dcd3..9fdd30e 100644 --- a/Marco.Pms.Model/ViewModels/PurchaseInvoice/PurchaseInvoiceAttachmentVM.cs +++ b/Marco.Pms.Model/ViewModels/PurchaseInvoice/PurchaseInvoiceAttachmentVM.cs @@ -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; } } } diff --git a/Marco.Pms.Services/Service/PurchaseInvoiceService.cs b/Marco.Pms.Services/Service/PurchaseInvoiceService.cs index a31d997..70a8b0b 100644 --- a/Marco.Pms.Services/Service/PurchaseInvoiceService.cs +++ b/Marco.Pms.Services/Service/PurchaseInvoiceService.cs @@ -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.ErrorResponse("Invalid attachment types", $"One or more attachment types are invalid: {string.Join(", ", invalidTypeIds)}", 400); - } - var preparedDocuments = new List(); var preparedAttachments = new List(); // 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.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.SuccessResponse(model, "Purchase invoice updated successfully.", 200); + var response = _mapper.Map(purchaseInvoice); + response.Project = projectVm; + + return ApiResponse.SuccessResponse(response, "Purchase invoice updated successfully.", 200); } catch (OperationCanceledException) {