public void ChangeProductName(ChangeProductNameCommand cmd) { if (_products.Any(x => x.Id == cmd.ProductId)) { Apply(new ProductNameChanged(cmd.ProductId, cmd.Name)); } }
public void ChangeProductName(ChangeProductNameCommand cmd) { if (_products.Any(x => x.Id == cmd.ProductId)) { var @event = new ProductNameChanged(cmd.ProductId, cmd.Name); Apply(@event); Dispatch(@event); } }
public async Task HandleAsync(ChangeProductNameCommand command, CancellationToken cancellationToken = default) { var aggregateProduct = await _repo.GetAsync(command.Id, cancellationToken : cancellationToken); if (aggregateProduct == null) { throw new CannotFindException("No data on this Id"); } aggregateProduct.ChangeProductName(command); await _repo.SaveAsync(aggregateProduct, cancellationToken); }
public CommandEvent When(ChangeProductNameCommand cmd) { var productCatalog = _factory.Load <ProductCatalogAggregate>(cmd.RootId); productCatalog.ChangeProductName(cmd); try { _eventStore.AppendToStream <ProductCatalogAggregate>(cmd.RootId, productCatalog.Version, productCatalog.Changes, productCatalog.DomainEvents.ToArray()); return(new CommandEvent(OperationStatus.Success)); } catch (EventStoreConcurrencyException ex) { HandleConcurrencyException(ex, productCatalog); return(new CommandEvent(OperationStatus.Success)); } catch (Exception) { throw; } }
public Result <object> When(ChangeProductNameCommand cmd) { while (true) { var productCatalog = _factory.Load <ProductCatalogAggregate>(cmd.RootId); productCatalog.ChangeProductName(cmd); try { _eventStore.AppendToStream <ProductCatalogAggregate>(cmd.RootId, productCatalog.Version, productCatalog.Changes); return(new Result <object>(null, new List <Exception>())); } catch (EventStoreConcurrencyException ex) { HandleConcurrencyException(ex, productCatalog); } catch (Exception) { throw; } } }
public Task HandleAsync(ChangeProductNameCommand command) { return(_writeRepository.UpdateNameAsync(command.Name, command.Id)); }
public void ChangeProductName(ChangeProductNameCommand command) { ApplyChange(new ChangedProductNameEvent(command.Name, this, command)); }
public async Task <IActionResult> ChangeProductName([FromBody] ChangeProductNameCommand command) { await _commandSender.SendAsync(command); return(Ok()); }
public async Task <IActionResult> ChangeProductNameAsync([FromBody] ChangeProductNameCommand command) { await Mediator.SendAsync(command).ConfigureAwait(false); return(Ok()); }
//Todo changeProductNameCommand Handler public Task HandleAsync(ChangeProductNameCommand command, CancellationToken cancellationToken = new CancellationToken()) { return(Task.CompletedTask); }