public Zendesk GetTicketInformation(string ticketNo)
        {
            Zendesk ticket = new Zendesk();

            try
            {
                long.TryParse(ticketNo, out long longTicketNo);

                ticket = ticket.VerifyInsertedZendeskTicket(longTicketNo);

                if (ticket != null)
                {
                    if (String.IsNullOrEmpty(ticket.FromEmailAddress) && String.IsNullOrEmpty(ticket.FromEmailName))
                    {
                        ticket.GetRequester();
                    }
                }
            }
            catch (Exception)
            {
                ticket = null;
            }

            return(ticket);
        }
예제 #2
0
        public bool VerifyInput(ref Zendesk zendeskTicket)
        {
            bool validInput = false;

            if (ExistingZendeskTicket)
            {
                if (SelectedZendeskTicket)
                {
                    cust = (Customer)Session["SelectedCustomer"];
                    foreach (SalesHeader head in cust.SalesHeader)
                    {
                        foreach (Zendesk ticket in head.Tickets)
                        {
                            if (!zendeskTickets.Any(t => t.TicketNo.Equals(ticket.TicketNo)))
                            {
                                zendeskTickets.Add(ticket);
                            }
                        }
                    }

                    foreach (ReturnHeader returnHead in cust.ReturnHeaders)
                    {
                        foreach (Zendesk ticket in returnHead.Tickets)
                        {
                            if (!zendeskTickets.Any(t => t.TicketNo.Equals(ticket.TicketNo)))
                            {
                                zendeskTickets.Add(ticket);
                            }
                        }
                    }

                    // TicketNo = ddlZendeskTickets.SelectedValue; ~ why are you here? Go away!

                    if (TicketNo != string.Empty)
                    {
                        foreach (Zendesk ticket in zendeskTickets)
                        {
                            if (ticket.TicketNo == TicketNo)
                            {
                                EmailSubject  = ticket.Subject;
                                FromEmail     = ticket.FromEmailAddress;
                                FromEmailName = ticket.FromEmailName;

                                EmailTo       = ticket.ToEmailsAddress;
                                zendeskTicket = ticket;
                            }
                        }

                        validInput = true;
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "selectValidTicketNo", "alert('Please select a valid existing Zendesk ticket when attempting to update a ticket number.');", true);
                    }
                }
                else if (InsertZendeskTicket)
                {
                    long.TryParse(InsertedZendeskTicket, out long ticketResult);

                    if (ticketResult != 0)
                    {
                        Zendesk Zendesk = new Zendesk();
                        zendeskTicket = Zendesk.VerifyInsertedZendeskTicket(ticketResult);

                        if (zendeskTicket != null)
                        {
                            if (String.IsNullOrEmpty(zendeskTicket.FromEmailAddress) && String.IsNullOrEmpty(zendeskTicket.FromEmailName))
                            {
                                zendeskTicket.GetRequester();
                            }

                            validInput = true;
                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "invalidZendeskTicket", "alert('The Zendesk ticket is invalid, please enter a valid ticket number.');", true);
                        }
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "invalidTicketNoInserted", "alert('Please insert a valid Zendesk ticket number.');", true);
                    }
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "invalidZendeskUpdateSelection", "alert('Please select a valid option to update existing Zendesk Ticket.');", true);
                }
            }
            else if (NewZendeskTicket)
            {
                if (HttpContext.Current.Session["ActiveUser"] != null)
                {
                    User u = (User)HttpContext.Current.Session["ActiveUser"];
                    FromEmail = u.ZendeskEmail;

                    EmailTo = CustomerEmailAddress;

                    string validateInput = ValidateInput(EmailTo, CustomerName);
                    if (validateInput != "Valid Input")
                    {
                        validInput = false;
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "unvalidatedData", "alert('" + validateInput + "');", true);
                    }
                    else
                    {
                        validInput = true;
                    }
                }
                else
                {
                    throw new Exception("Unable to retrieve current Zendesk Email address.");
                }
            }
            else if (DownloadManually)
            {
                validInput = true;
            }
            else if (GenerateURL)
            {
                validInput = true;
            }

            return(validInput);
        }