protected override async Task HandleCore(TicketStatusDomainEvent message) { var ticketTask = _ticketRepository.Find(message.AggregateRootId.ToString()); var oldStatusTask = _statusRepository.Find(message.FromStatusId); var newStatusTask = _statusRepository.Find(message.ToStatusId); await Task.WhenAll(ticketTask, oldStatusTask, newStatusTask); var ticket = ticketTask.Result; var oldStatus = oldStatusTask.Result; var newStatus = newStatusTask.Result; // Update ticket in ReadModel ticket.Status = newStatus; // Add ticket event in ReadModel var ticketEvent = new StatusEventDto(oldStatus, newStatus) { Id = Guid.NewGuid().ToString(), TicketId = message.AggregateRootId.ToString(), Created = message.Created, UserId = message.UserId.ToString(), }; await Task.WhenAll( _ticketRepository.Update(ticket), _eventRepository.Add(ticketEvent)); await _websocketEmittor.Emit( new ReduxUpdateStatusAction(_mapper.Map <TicketStatusEventViewModel>(ticketEvent))); }
public async Task Handle(TicketCreateEvent message) { var priority = _priorityRepository.Find(message.PriorityId); var status = _statusRepository.Find(message.StatusId); await Task.WhenAll(priority, status); var ticket = new TicketDto { Id = message.AggregateRootId.ToString(), Description = message.Description, Title = message.Title, Priority = priority.Result, Status = status.Result, Files = message.Files?.Select(f => new FileDto { Id = f.Id.ToString(), Name = f.Name, Type = f.Type, Size = f.Size }).ToList() }; var @event = new CreatedEventDto { Id = Guid.NewGuid().ToString(), TicketId = message.AggregateRootId.ToString(), Created = message.Created, UserId = message.UserId.ToString(), }; await Task.WhenAll(AddInDb(ticket, @event), EmitToFrontEnd(ticket, @event)); }