Skip to content

Commit 05c0bb5

Browse files
authored
feat(templates): improve bit Boilerplate product image upload #11107 (#11109)
1 parent 29d621c commit 05c0bb5

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Products/AddOrEditProductPage.razor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ private async Task HandleOnUploadComplete(BitFileInfo fileInfo)
9191
{
9292
product.HasPrimaryImage = true;
9393
product.PrimaryImageAltText = fileInfo.Message;
94-
product.ConcurrencyStamp = Guid.NewGuid().ToByteArray(); // To update the product image's url when user changes product image multiple time within the same page.
9594
isManagingFile = false;
9695
}
9796

@@ -109,7 +108,10 @@ private async Task RemoveProductImage()
109108
try
110109
{
111110
await attachmentController.DeleteProductPrimaryImage(product.Id, CurrentCancellationToken);
112-
product.HasPrimaryImage = false;
111+
if (Id is not null)
112+
{
113+
product = await productController.Get(Id.Value, CurrentCancellationToken); // To get latest concurrency stamp and other properties modified by the server.
114+
}
113115
}
114116
catch (KnownException e)
115117
{

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ private async Task DeleteAttachment(Guid attachmentId, AttachmentKind[] kinds, C
121121
if (product is not null) // else means product is being added to the database.
122122
{
123123
product.HasPrimaryImage = false;
124+
product.PrimaryImageAltText = null;
124125
await DbContext.SaveChangesAsync(cancellationToken);
125126
await responseCacheService.PurgeProductCache(product.ShortId);
126127
}
@@ -233,14 +234,6 @@ private async Task<IActionResult> UploadAttachment(Guid attachmentId, Attachment
233234
altText = response.Result.Alt;
234235
}
235236
//#endif
236-
237-
var product = await DbContext.Products.FindAsync([attachment.Id], cancellationToken);
238-
if (product is not null) // else means product is being added to the database.
239-
{
240-
product.HasPrimaryImage = true;
241-
await DbContext.SaveChangesAsync(cancellationToken);
242-
await responseCacheService.PurgeProductCache(product.ShortId);
243-
}
244237
}
245238
//#endif
246239

@@ -281,10 +274,6 @@ private string GetFilePath(Guid attachmentId, AttachmentKind kind, string? fileN
281274
}
282275

283276
//#if (signalR == true || database == "PostgreSQL" || database == "SqlServer")
284-
public class AIImageReviewResponse
285-
{
286-
public bool IsCar { get; set; }
287-
public string? Alt { get; set; }
288-
}
277+
public record AIImageReviewResponse(bool IsCar, string? Alt);
289278
//#endif
290279
}

0 commit comments

Comments
 (0)