/// <summary> /// Implementation of <see cref="ICustomerCommands.DeleteCustomer(Guid)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <returns></returns> public async Task DeleteCustomer(Guid customerId) { if (customerId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(customerId)); } var customer = await Repository.GetByKeyAsync <Customer>(customerId); if (customer == null) { throw new ArgumentOutOfRangeException(nameof(customerId)); } try { customer.Delete(); if (customer.HasAccount) { await AuthClient.DisableAccount(customer.Account.UserId); customer.LockAccount(); } await Repository.SaveChangesAsync(); var @event = new CustomerDeletedEvent(customerId); EventBus.RaiseEvent(@event); } catch { throw; } }
/// <summary> /// DELETE /api/customers/{id} /// </summary> /// <param name="id"></param> /// <param name="data"></param> /// <returns></returns> public HttpResponseMessage Delete(int id, CustomerModel model) { var context = this.DbContext; var entity = context.Customers.Find(id); if (entity == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } if (!this.User.CanDelete(entity)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } // create the web event var webEvent = new CustomerDeletedEvent(entity); // delete the entity context.Customers.Remove(entity); // persist changes to the database context.SaveChanges(); // fire the web event webEvent.Raise(); return(new HttpResponseMessage(HttpStatusCode.NoContent)); }
public void Ctor_Should_Set_All_Values_Correctly() { Guid customerId = Guid.NewGuid(); var ev = new CustomerDeletedEvent(customerId); Assert.Equal(customerId, ev.CustomerId); Assert.Equal(customerId, ev.AggregateId); Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType); }
public void ToString_Should_Return_Event_Formatted_As_String() { Guid customerId = Guid.NewGuid(); var ev = new CustomerDeletedEvent(customerId); string eventAsString = $"Customer {customerId} deleted"; Assert.Equal(eventAsString, ev.ToString()); }
/// <summary> /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/> /// </summary> /// <param name="event"></param> public void Handle(CustomerDeletedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public async Task Handle(DeleteCustomerCommand command, CancellationToken cancellationToken) { var DeletedEvent = new CustomerDeletedEvent { CustomerId = command.CustomerId, CreatedAt = DateTime.Now }; // Insert event to Command Db await _eventSources.InserEvent(DeletedEvent, cancellationToken); await _kafkaProducer.Send(DeletedEvent, "PosServices"); }
private void HandleDomainEvent(DomainEvent evt) { var _ = evt switch { CustomerAddedEvent castedEvt => ApplyEventToState(castedEvt), CustomerModifiedEvent castedEvt => ApplyEventToState(castedEvt), CustomerDeletedEvent castedEvt => ApplyEventToState(castedEvt), RebuildStateEvent castedEvt => ApplyEventToState(castedEvt), _ => false, }; RaiseOnStateChanged(); }
public async Task ExecuteAsync(HookType type, IDomainEntityContext <Customer> context, CancellationToken cancellationToken) { switch (context.EditMode) { case EditMode.Create: await context.AddEventAsync(CustomerCreatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; case EditMode.Update: await context.AddEventAsync(CustomerUpdatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; case EditMode.Delete: await context.AddEventAsync(CustomerDeletedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken); break; } }
public void Handle(CustomerDeletedEvent e) { this.Version = e.Version; this.State = e.State; }
/// <summary> /// 删除一个实体后激活此事件 /// </summary> /// <param name="notification"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task Handle(CustomerDeletedEvent notification, CancellationToken cancellationToken) { //刷新缓存或者其他操作 return(Task.CompletedTask); }
internal void Apply(CustomerDeletedEvent ev) { IsDeleted = true; }
public void Handle(CustomerDeletedEvent message) { this._db.Update(message.AggregateId, message.State, message.Version); }