diff --git a/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs b/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs index 0431a25ec..595eaec71 100644 --- a/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs +++ b/Sheaft.Application/Interfaces/Infrastructure/IPictureService.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Sheaft.Core; +using Sheaft.Domain; namespace Sheaft.Application.Interfaces.Infrastructure { @@ -12,5 +14,6 @@ public interface IPictureService Task> HandleProductPictureAsync(Domain.Product product, Guid pictureId, string picture, CancellationToken token); Task> HandleTagPictureAsync(Domain.Tag tag, string picture, CancellationToken token); Task> HandleTagIconAsync(Domain.Tag tag, string icon, CancellationToken token); + string GetDefaultProductPicture(IEnumerable tags); } } \ No newline at end of file diff --git a/Sheaft.Infrastructure/Services/PictureService.cs b/Sheaft.Infrastructure/Services/PictureService.cs index 2850bb42f..d1d3b7322 100644 --- a/Sheaft.Infrastructure/Services/PictureService.cs +++ b/Sheaft.Infrastructure/Services/PictureService.cs @@ -132,7 +132,7 @@ await UploadProductPreviewAsync(image, entity.ProducerId, entity.Id, pictureId, } } - private string GetDefaultProductPicture(IEnumerable tags) + public string GetDefaultProductPicture(IEnumerable tags) { var category = tags.FirstOrDefault(t => t.Kind == TagKind.Category); return category?.Picture; diff --git a/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs b/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs index f653d2e1e..b4e73abd0 100644 --- a/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs +++ b/Sheaft.Mediatr/Product/Commands/CreateProductCommand.cs @@ -152,6 +152,11 @@ await _context.Products.AnyAsync( if (!result.Succeeded) return Failure(result); } + else + { + var picture = _imageService.GetDefaultProductPicture(tags); + entity.AddPicture(new ProductPicture(Guid.NewGuid(), picture, 0)); + } await _context.SaveChangesAsync(token); await transaction.CommitAsync(token); diff --git a/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs b/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs index 6abcd509d..f96679067 100644 --- a/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs +++ b/Sheaft.Mediatr/Product/Commands/UpdateProductCommand.cs @@ -161,7 +161,12 @@ public async Task Handle(UpdateProductCommand request, CancellationToken if (!result.Succeeded) return Failure(result); } - + else + { + var picture = _imageService.GetDefaultProductPicture(tags); + entity.AddPicture(new ProductPicture(Guid.NewGuid(), picture, 0)); + } + await _context.SaveChangesAsync(token); await transaction.CommitAsync(token);