Exemple #1
0
        /// <inheritdoc />
        /// <exception cref="UnauthorizedAccessException">Thrown if the user doesn't own the ticket</exception>
        public async Task VerifyTicket(TicketVerifyBody ticketVerifyBody)
        {
            var ticket = await ApplicationContext.Tickets
                         .Include(x => x.Event)
                         .FirstOrDefaultAsync(x => x.Id == ticketVerifyBody.Id && x.Event.Id == ticketVerifyBody.EventId);

            if (ticket == null)
            {
                throw new UnauthorizedAccessException();
            }

            ticket.Uses++;

            try
            {
                WorkQueue.QueueWork(token =>
                                    AnalyticsService.CaptureTicketVerifyAsync(token, ticket.Id, ticketVerifyBody.EventId,
                                                                              DateTime.Now));

                WorkQueue.QueueWork(token =>
                                    RecommendationService.InfluenceAsync(token, ticket.User.Id, ticket.Event.Id, Influence.Verify,
                                                                         DateTime.Now));

                await ApplicationContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Logger.LogInformation(e.ToString());
                throw;
            }
        }
        public async Task <ActionResult> Verify(TicketVerifyBody ticketVerifyBody)
        {
            try
            {
                Logger.LogInformation("Verifying {Id} for {Event}", ticketVerifyBody.Id, ticketVerifyBody.EventId);
                await TicketService.VerifyTicket(ticketVerifyBody);

                return(Ok());
            }
            catch (Exception e)
            {
                Logger.LogInformation(e.ToString());
                return(Unauthorized(e));
            }
        }