public IActionResult CheckTicket(string barcode, int eventId)
        {
            Console.WriteLine(barcode);
            var ticketsResponse = new TicketResponse <Tickets>()
            {
                Error = true // default
            };

            if (barcode == null)
            {
                ticketsResponse.Message = "Barcode null";
                return(BadRequest(ticketsResponse));
            }

            try
            {
                var ticket = ticketServices.GetTicket(barcode, eventId);
                if (ticket == null)
                {
                    return(NotFound($"Ticket not found, barcode {barcode}"));
                }

                ticketsResponse.Error   = false;
                ticketsResponse.Message = "Valid";
                ticketsResponse.ticket  = CreateResponseTicket(ticket);
                if (!ticket.IsActivated)
                {
                    if (ticketServices.UpdateTicket(ticket))
                    {
                        Console.WriteLine("Updated");
                        return(Ok(ticketsResponse));
                    }
                    else
                    {
                        ticketsResponse.Error   = true;
                        ticketsResponse.Message = "Error while updating the ticket";
                        return(StatusCode(500, ticketsResponse));
                    }
                }
                else
                {
                    // ticket is already activated, no need for updating
                    return(Ok(ticketsResponse));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ticketsResponse.Error   = true;
                ticketsResponse.Message = e.Message;
                return(StatusCode(500, ticketsResponse));
            }
        }
Exemplo n.º 2
0
 public IActionResult GetTicket(int id)
 {
     return(Ok(_ticketServices.GetTicket(id)));
 }