diff --git a/Sheaft.Application.Commands/Product/ImportProductsCommand.cs b/Sheaft.Application.Commands/Product/ImportProductsCommand.cs index 69107760e..1db12d517 100644 --- a/Sheaft.Application.Commands/Product/ImportProductsCommand.cs +++ b/Sheaft.Application.Commands/Product/ImportProductsCommand.cs @@ -12,5 +12,6 @@ public ImportProductsCommand(RequestUser requestUser) : base(requestUser) } public Guid Id { get; set; } + public bool NotifyOnUpdates { get; set; } = true; } } diff --git a/Sheaft.Application.Commands/Product/QueueImportProductsCommand.cs b/Sheaft.Application.Commands/Product/QueueImportProductsCommand.cs index 811621fc0..c4b6b6a23 100644 --- a/Sheaft.Application.Commands/Product/QueueImportProductsCommand.cs +++ b/Sheaft.Application.Commands/Product/QueueImportProductsCommand.cs @@ -15,5 +15,6 @@ public QueueImportProductsCommand(RequestUser requestUser) : base(requestUser) public Guid Id { get; set; } public string FileName { get; set; } public byte[] FileStream { get; set; } + public bool NotifyOnUpdates { get; set; } = true; } } diff --git a/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs index 648d795d0..574f7a403 100644 --- a/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs @@ -262,7 +262,7 @@ public async Task> Handle(QueueImportProductsCommand request, Cance await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); - _mediatr.Post(new ImportProductsCommand(request.RequestUser) { Id = entity.Id }); + _mediatr.Post(new ImportProductsCommand(request.RequestUser) { Id = entity.Id, NotifyOnUpdates = request.NotifyOnUpdates }); return Created(entity.Id); }); } @@ -280,7 +280,8 @@ public async Task> Handle(ImportProductsCommand request, Cancellati if (!startResult.Success) throw startResult.Exception; - _mediatr.Post(new ProductImportProcessingEvent(request.RequestUser) { JobId = job.Id }); + if(request.NotifyOnUpdates) + _mediatr.Post(new ProductImportProcessingEvent(request.RequestUser) { JobId = job.Id }); var data = await _blobService.DownloadImportProductsFileAsync(job.User.Id, job.Id, token); if (!data.Success) @@ -319,12 +320,16 @@ public async Task> Handle(ImportProductsCommand request, Cancellati if (!result.Success) throw result.Exception; - _mediatr.Post(new ProductImportSucceededEvent(request.RequestUser) { JobId = job.Id }); + if (request.NotifyOnUpdates) + _mediatr.Post(new ProductImportSucceededEvent(request.RequestUser) { JobId = job.Id }); + return result; } catch (Exception e) { - _mediatr.Post(new ProductImportFailedEvent(request.RequestUser) { JobId = job.Id }); + if (request.NotifyOnUpdates) + _mediatr.Post(new ProductImportFailedEvent(request.RequestUser) { JobId = job.Id }); + return await _mediatr.Process(new FailJobCommand(request.RequestUser) { Id = job.Id, Reason = e.Message }, token); } }); diff --git a/Sheaft.Web.Manage/Controllers/ProductsController.cs b/Sheaft.Web.Manage/Controllers/ProductsController.cs index ac0854828..79f81296f 100644 --- a/Sheaft.Web.Manage/Controllers/ProductsController.cs +++ b/Sheaft.Web.Manage/Controllers/ProductsController.cs @@ -231,7 +231,7 @@ public async Task Import(IEnumerable products, Cancell using (var stream = new MemoryStream()) { await formFile.CopyToAsync(stream, token); - var result = await _mediatr.Process(new QueueImportProductsCommand(requestUser) { Id = requestUser.Id, FileName = formFile.FileName, FileStream = stream.ToArray() }, token); + var result = await _mediatr.Process(new QueueImportProductsCommand(requestUser) { Id = requestUser.Id, NotifyOnUpdates = false, FileName = formFile.FileName, FileStream = stream.ToArray() }, token); if (!result.Success) return BadRequest(result); }