public async Task Handle(TicketPriorityEvent message)
        {
            var ticketTask      = _ticketRepository.Find(message.AggregateRootId.ToString());
            var oldPriorityTask = _priorityRepository.Find(message.FromPriorityId);
            var newPriorityTask = _priorityRepository.Find(message.ToPriorityId);

            await Task.WhenAll(ticketTask, oldPriorityTask, newPriorityTask);

            var ticket      = ticketTask.Result;
            var oldPriority = oldPriorityTask.Result;
            var newPriority = newPriorityTask.Result;

            // Update ticket in ReadModel
            ticket.Priority = newPriority;

            // Add ticket event in ReadModel
            var ticketEvent = new PriorityEventDto(oldPriority, newPriority)
            {
                Id       = Guid.NewGuid().ToString(),
                TicketId = message.AggregateRootId.ToString(),
                Created  = message.Created,
                UserId   = message.UserId.ToString(),
            };

            await Task.WhenAll(
                _websocketEmittor.Emit(new ReduxUpdatePriorityAction(_mapper.Map <TicketPriorityEventViewModel>(ticketEvent))),
                _ticketRepository.Update(ticket),
                _eventRepository.Add(ticketEvent));
        }
Ejemplo n.º 2
0
        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)));
        }
        private Task EmitToFrontEnd(TicketDto ticketDto, TicketEventDto eventDto)
        {
            var vm = _mapper.Map <TicketViewModel>(ticketDto);

            vm.Events = new List <TicketEventViewModel> {
                _mapper.Map <TicketCreatedEventViewModel>(eventDto)
            };

            return(_websocketEmittor.Emit(new ReduxTicketCreateAction(vm)));
        }
        public Task Handle(TicketCommentEvent message)
        {
            var ticketEvent = new CommentEventDto
            {
                Id       = Guid.NewGuid().ToString(),
                TicketId = message.AggregateRootId.ToString(),
                Created  = message.Created,
                UserId   = message.UserId.ToString(),
                Comment  = message.Comment
            };

            return(Task.WhenAll(
                       _websocketEmittor.Emit(new ReduxCommentAddedAction(_mapper.Map <TicketCommentEventViewModel>(ticketEvent))),
                       _repository.Add(ticketEvent)));
        }
        protected override async Task HandleCore(TicketCommentDomainEvent message)
        {
            var ticketEvent = new CommentEventDto
            {
                Id       = Guid.NewGuid().ToString(),
                TicketId = message.AggregateRootId.ToString(),
                Created  = message.Created,
                UserId   = message.UserId.ToString(),
                Comment  = message.Comment
            };

            await _repository.Add(ticketEvent);

            await _websocketEmittor.Emit(
                new ReduxCommentAddedAction(_mapper.Map <TicketCommentEventViewModel>(ticketEvent)));
        }
 private Task EmitToFrontEnd(PriorityEventDto eventDto)
 {
     return(_websocketEmittor.Emit(
                new ReduxUpdatePriorityAction(_mapper.Map <TicketPriorityEventViewModel>(eventDto))));
 }