Skip to content

Commit

Permalink
Fix - Génération d'une référence d'un produit à l'update
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier committed Nov 9, 2020
1 parent 17d6cab commit 1b9ce53
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sheaft.Application.Handlers/Commands/ProductCommandsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ public async Task<Result<bool>> Handle(UpdateProductCommand request, Cancellatio
{
var entity = await _context.GetByIdAsync<Product>(request.Id, token);
if (!string.IsNullOrWhiteSpace(request.Reference) && request.Reference != entity.Reference)
{
var existingEntity = await _context.FindSingleAsync<Product>(p => p.Reference == request.Reference && p.Producer.Id == request.RequestUser.Id, token);
if (existingEntity != null)
return ValidationError<bool>(MessageKind.CreateProduct_Reference_AlreadyExists, request.Reference);
}
if(string.IsNullOrWhiteSpace(request.Reference))
{
var resultIdentifier = await _mediatr.Process(new CreateProductIdentifierCommand(request.RequestUser) { ProducerId = request.RequestUser.Id }, token);
if (!resultIdentifier.Success)
return Failed<bool>(resultIdentifier.Exception);
request.Reference = resultIdentifier.Data;
}
entity.SetVat(request.Vat);
entity.SetName(request.Name);
entity.SetDescription(request.Description);
Expand Down

0 comments on commit 1b9ce53

Please sign in to comment.