public async Task <TicketDTO> Handle(CreateTicketCommand message, CancellationToken cancellationToken) { var seat = _seatingRepository.GetAsync(message.SeatId); if (seat == null) { throw new ArgumentNullException(nameof(seat)); } if (seat.Result.IsOccupied) { throw new TicketingDomainException("Seat is already occupied"); } var customer = _customerRepository.GetAsync(message.SeatId); if (seat == null) { throw new ArgumentNullException(nameof(seat)); } var ticket = new Ticket(message.SeatId, message.CustomerId); Log.Information($"Creating Ticket: {ticket}"); _ticketRepository.Add(ticket); await _ticketRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); var result = new TicketDTO() { TicketId = ticket.Id, CreatedOn = Timestamp.FromDateTime(ticket.CreatedOn) }; return(await Task.FromResult(result)); }
public async Task Handle(TicketCreatedDomainEvent ticketCreatedEvent, CancellationToken cancellationToken) { Log.Information($"TicketCreatedDomainEvent happened..."); var seatToUpdate = await _seatingRepository.GetAsync(ticketCreatedEvent.SeatId); if (seatToUpdate == null) { Log.Error($"Error updating seat {ticketCreatedEvent.SeatId}; seat does not exist"); } seatToUpdate?.SetIsOccupied(true); await _seatingRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); }