Beispiel #1
0
        private void HandleTicketResponse(TicketsResponse <Ticket> ticketResponse, string scannedBarcode)
        {
            if (ticketResponse.Error)
            {
                MessageBox.Show($"Error validating ticket: {ticketResponse.Message}");
            }
            else
            {
                lblBarcode.Text = scannedBarcode;
                if (ticketResponse.Ticket.IsActivated)
                {
                    colorPanel.BackColor = Color.Firebrick;
                    lblValid.Text        = "INVALID";

                    string timeFormated = ticketResponse.Ticket.ActivatedAt != null?
                                          DateTime.Parse(ticketResponse.Ticket.ActivatedAt).ToString("yyyy-MM-dd HH:mm:ss") : "";

                    lblActivatedAt.Text = "Activated at " + timeFormated;
                }
                else
                {
                    colorPanel.BackColor = Color.OliveDrab;
                    lblValid.Text        = "VALID";
                    lblActivatedAt.Text  = "Activating at " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //UpdateStatsForm(ticketResponse.Ticket); // updating the statistics screen ( if its activated )
                }
            }
        }
Beispiel #2
0
        public List <Ticket> GetTicketsAsync(string token)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                var authHeader = new AuthenticationHeaderValue("Bearer", token);
                httpClient.DefaultRequestHeaders.Authorization = authHeader;

                Task <String> response = httpClient.GetStringAsync(Configuration.TicketsApiEndpoint);
                if (response.Result.Contains("xmlPayload"))
                {
                    TicketsResponse ticketsResponse = JsonConvert.DeserializeObject <TicketsResponse>(response.Result);
                    return(ticketsResponse.xmlPayload);
                }
                else
                {
                    return(JsonConvert.DeserializeObject <List <Ticket> >(response.Result));
                }
            }
        }
        public async Task <TicketsResponse <Ticket> > CheckTicket(string barcode)
        {
            var httpRequestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri($"{HttpClientBuilder.BaseUrl}{chosenEvent.Id}/ticket/{barcode}"),
                Headers    =
                {
                    { HttpRequestHeader.Authorization.ToString(), $"Bearer {token}" }
                }
            };

            var response = await HttpClientBuilder.HttpClient.SendAsync(httpRequestMessage);

            if (response.IsSuccessStatusCode)
            {
                if (response.Content == null)
                {
                    return(new TicketsResponse <Ticket>()
                    {
                        Error = true,
                        Message = "Content null",
                        Ticket = null
                    });
                }

                TicketsResponse <Ticket> ticketResponse =
                    await response.Content.ReadAsAsync <TicketsResponse <Ticket> >();

                return(ticketResponse);
            }
            else
            {
                return(new TicketsResponse <Ticket>()
                {
                    Error = true,
                    Message = response.ReasonPhrase,
                    Ticket = null
                });
            }
        }
Beispiel #4
0
        public static async Task <TicketsResponse <List <Ticket> > > DownloadTickets(TicketHandler ticketHandler, string type)
        {
            if (ticketHandler != null)
            {
                TicketsResponse <List <Ticket> > response = await ticketHandler.GetTickets(type);

                if (response == null)
                {
                    MessageBox.Show("Response body null, please check your internet connection.");
                    return(null);
                }

                if (response.Error)
                {
                    MessageBox.Show($"Error while downloading {type} tickets: " + response.Message);
                    return(null);
                }
                else
                {
                    if (type.Equals("active"))
                    {
                        Console.WriteLine("Active tickets: " + response.Ticket.Count);
                    }
                    else if (type.Equals("inactive"))
                    {
                        Console.WriteLine("InActive tickets: " + response.Ticket.Count);
                    }

                    if (response.Ticket == null)
                    {
                        response.Ticket = new List <Ticket>();
                    }
                    return(response);
                }
            }
            else
            {
                MessageBox.Show($"Cant download {type} tickets. Ticket handler is not initialized.");
                return(null);
            }
        }
        /// <summary>
        /// Recupera de forma paginada os tickets, com as referencias populadas
        /// </summary>
        /// <param name="advancedFilter"></param>
        /// <returns></returns>
        public TicketsResponse GetAllPaged(FilterRequest advancedFilter)
        {
            var result   = new TicketsResponse();
            var sql      = string.Empty;
            var sqlCount = string.Empty;

            try
            {
                using (var conn = CreateConnection())
                {
                    result.TotalGeral = (int)conn.ExecuteScalar("SELECT COUNT(*) FROM Ticket");

                    sql      = RecuperarQuery(Tipos.TipoConsulta.Paged, advancedFilter);
                    sqlCount = RecuperarQuery(Tipos.TipoConsulta.Count, advancedFilter);

                    result.TotalFiltrado = (int)conn.ExecuteScalar(sqlCount);

                    result.Tickets = conn.Query <Ticket, Categoria, Classificacao, StatusTicket, UsuarioCliente, Ticket>(sql,
                                                                                                                         map: (ticket, categoria, classificacao, status, usuario) =>
                    {
                        ticket.Categoria      = categoria;
                        ticket.Classificacao  = classificacao;
                        ticket.StatusTicket   = status;
                        ticket.UsuarioCliente = usuario;

                        return(ticket);
                    },
                                                                                                                         splitOn: "id_categoria_entity,id_classificacao_entity,id_status_ticket_entity,id_usuario_cliente_enttity").Distinct().ToList();
                }

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }