Exemplo n.º 1
0
        /// <summary>
        /// After ticket registration, immediately verify if it's a lottery ticket.
        /// </summary>
        public async Task ReportOnLottery(MovieTicket ticket, string connectionId)
        {
            var movieId   = Guid.Parse(ticket.MovieId);
            var theaterId = Guid.Parse(ticket.TheaterId);

            var movie = db.Query <Movie>()
                        .Where(s => s.Id == movieId)
                        .Single();

            if (movie.TicketType == TicketType.DrawingTicket)
            {
                var theater = TheatersContext.GetTheaters().Single(s => s.Id == theaterId);

                var message = new
                {
                    Theater         = theater.Name,
                    MovieTitle      = movie.Title,
                    Time            = ticket.Time,
                    NumberOfTickets = ticket.NumberOfTickets,
                    DrawingDate     = DateTime.Now.AddDays(14).ToString("dddd, dd MMMM", CultureInfo.InvariantCulture)
                };

                logger.LogInformation("Sending OrderedLotteryTicket", message);

                await hub.Clients.Client(connectionId).SendAsync("OrderedLotteryTicket", message);
            }
        }
Exemplo n.º 2
0
        public async Task SubmitOrder(MovieTicket ticket)
        {
            var userConnectionId = this.Context.ConnectionId;

            var sendOptions = new SendOptions();

            sendOptions.SetHeader("SignalRConnectionId", userConnectionId);

            var order = new SubmitOrder
            {
                Theater         = Guid.Parse(ticket.TheaterId),
                Movie           = Guid.Parse(ticket.MovieId),
                Time            = ticket.Time,
                NumberOfTickets = ticket.NumberOfTickets,
                UserId          = Guid.Parse("218d92c4-9c42-4e61-80fa-198b22461f61") // For now, no other users allowed ;-)
            };

            await messageSession.Send(order, sendOptions).ConfigureAwait(false);

            await movieTickets.ReportOnLottery(ticket, Context.ConnectionId);
        }