Exemple #1
0
        public async Task Handle(RaffleItemUpdated notification, CancellationToken cancellationToken)
        {
            var raffleItem   = RaffleItemDuringRunMapper.Map(notification.RaffleItem);
            var ordersResult = await mediator.Send(new GetRaffleOrdersQuery());

            var possibleWinners = ordersResult.Orders.Select(x =>
                                                             new
            {
                Name    = $"{x.Customer.FirstName} {x.Customer.LastName}",
                Tickets = GetOrderTickets(x.TicketNumber)
            });

            foreach (var winningTicket in raffleItem.WinningTickets)
            {
                var winner = possibleWinners.Where(x => x.Tickets.Contains(winningTicket.Number)).FirstOrDefault();
                raffleItem.Winners.Add(new Winner {
                    Name = winner.Name, For = winningTicket.For, TicketNumber = winningTicket.Number
                });
            }

            await hub.Clients.All.RaffleItemUpdated(raffleItem);
        }
Exemple #2
0
 public Task RaffleItemUpdated(RaffleItem raffleItem)
 {
     return(Clients.All.RaffleItemUpdated(RaffleItemDuringRunMapper.Map(raffleItem)));
 }