예제 #1
0
        /// <summary>
        /// Add the Tag tags to the final xml of the deleted tickets
        /// </summary>
        /// <param name="deletedTicketsXml">Deleted Tickets xml string.</param>
        /// <returns>An xml string with the Deleted Tickets data and its tags.</returns>
        private static string AddTagsToDeletedTickets(string deletedTicketsXml, RestCommand command, bool isCustomerToken = false)
        {
            string xml = string.Empty;
            //Add the tag nodes to each deleted ticket object
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.XmlResolver = null;
            xmlDoc.LoadXml(deletedTicketsXml);

            //Do we have paging?
            XmlNode totalRecordsElement = xmlDoc.SelectSingleNode("/DeletedTickets/TotalRecords");

            XmlNodeList nodeList        = xmlDoc.SelectNodes("/DeletedTickets/DeletedTicket");
            string      xmlResultString = string.Empty;

            using (var xmlTextWriter = Tickets.BeginXmlWrite("DeletedTickets"))
            {
                if (totalRecordsElement != null)
                {
                    totalRecordsElement.WriteTo(xmlTextWriter);
                    totalRecordsElement = null;
                }

                foreach (XmlNode node in nodeList)
                {
                    //get the tags for the deleted ticket using the Id
                    try
                    {
                        string recordIdString = node["ID"].InnerText;
                        Tags   tags           = new Tags(command.LoginUser);
                        tags.LoadByReference(ReferenceType.DeletedTickets, int.Parse(recordIdString), isCustomerToken ? command.Organization.ParentID : null);
                        XmlTextWriter writer = Tags.BeginXmlWrite("Tags");

                        foreach (DataRow row in tags.Table.Rows)
                        {
                            tags.WriteXml(writer, row, "Tag", false, null);
                        }

                        string tagXmlString = string.Empty;
                        tagXmlString = Tags.EndXmlWrite(writer);
                        XmlDocument xmlTag = new XmlDocument();
                        xmlDoc.XmlResolver = null;
                        xmlTag.LoadXml(tagXmlString);
                        node.AppendChild(node.OwnerDocument.ImportNode(xmlTag.FirstChild.NextSibling, true));
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogs.LogException(command.LoginUser, ex, "API", string.Format("OrgID: {0}{1}Verb: {2}{1}Url: {3}{1}Body: {4}", command.Organization.OrganizationID, Environment.NewLine, command.Method, command.Method, command.Data));
                    }

                    node.WriteTo(xmlTextWriter);
                }

                xml = DeletedTickets.EndXmlWrite(xmlTextWriter);
            }

            return(xml);
        }
예제 #2
0
        public static string GetTicketsByCustomerID(RestCommand command, int customerID, bool orderByDateCreated = false)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);
            string      orderBy = orderByDateCreated ? "ot.DateCreated DESC" : "TicketNumber";
            string      xml     = "";

            if (command.IsPaging)
            {
                try
                {
                    //remove Paging parameters
                    NameValueCollection filters = new NameValueCollection();

                    foreach (string key in command.Filters.AllKeys)
                    {
                        if (key.ToLower() != "pagenumber" && key.ToLower() != "pagesize")
                        {
                            filters.Add(key, command.Filters[key]);
                        }
                    }

                    tickets.LoadByCustomerID(customerID, filters, (int)command.PageNumber, (int)command.PageSize, orderBy);
                    XmlTextWriter writer = Tickets.BeginXmlWrite("Tickets");

                    foreach (DataRow row in tickets.Table.Rows)
                    {
                        int  ticketId = (int)row["TicketID"];
                        Tags tags     = new Tags(command.LoginUser);
                        tags.LoadByReference(ReferenceType.Tickets, ticketId);
                        tags = tags ?? new Tags(command.LoginUser);
                        tickets.WriteXml(writer, row, "Ticket", true, new NameValueCollection(), tags);
                    }

                    int totalRecords = 0;

                    if (tickets.Count > 0)
                    {
                        totalRecords = tickets[0].TotalRecords;
                    }

                    writer.WriteElementString("TotalRecords", totalRecords.ToString());
                    xml = Tickets.EndXmlWrite(writer);
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTicketsByCustomerID(). Paging. SQL filtering generation failed.");
                    throw new RestException(HttpStatusCode.InternalServerError, "There was an error processing your request. Please contact TeamSupport.com", ex);
                }
            }
            else
            {
                tickets.LoadByCustomerID(customerID, orderBy);
                xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters, command.IsPaging);
                xml = AddTagsToTickets(xml, command);
            }

            return(xml);
        }
        public static string GetTickets(RestCommand command)
        {
            string xml = "";

            if (command.Filters["TicketTypeID"] != null)
            {
                try
                {
                    ReportTicketsView tickets = new ReportTicketsView(command.LoginUser);
                    int        ticketTypeID   = int.Parse(command.Filters["TicketTypeID"]);
                    TicketType ticketType     = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                    if (ticketType.OrganizationID != command.Organization.OrganizationID)
                    {
                        throw new Exception();
                    }
                    tickets.LoadByTicketTypeID(ticketTypeID);
                    xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters);
                }
                catch (Exception ex)
                {
                    throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                }
            }
            else
            {
                TicketTypes ticketTypes = new TicketTypes(command.LoginUser);
                ticketTypes.LoadByOrganizationID(command.Organization.OrganizationID);

                ReportTicketsView tickets = new ReportTicketsView(command.LoginUser);
                XmlTextWriter     writer  = Tickets.BeginXmlWrite("Tickets");

                foreach (TicketType ticketType in ticketTypes)
                {
                    tickets.LoadByTicketTypeID(ticketType.TicketTypeID);
                    //writer.WriteStartElement(ticketType.Name);
                    foreach (DataRow row in tickets.Table.Rows)
                    {
                        tickets.WriteXml(writer, row, "Ticket", true, command.Filters);
                    }
                    //writer.WriteEndElement();
                }

                xml = Tickets.EndXmlWrite(writer);
            }

            //return tickets.GetXml("Tickets", "Ticket", command.Filters["TicketTypeID"] != null, command.Filters);
            return(xml);
        }
예제 #4
0
        public static string GetZapierTickets(RestCommand command, int limitNumber)
        {
            string xml = "";

            TicketsView   tickets = new TicketsView(command.LoginUser);
            XmlTextWriter writer  = Tickets.BeginXmlWrite("Tickets");

            tickets.LoadByOrganizationIDOrderByNumberDESC(command.Organization.OrganizationID, limitNumber);
            foreach (DataRow row in tickets.Table.Rows)
            {
                tickets.WriteXml(writer, row, "Ticket", true, command.Filters);
            }

            xml = Tickets.EndXmlWrite(writer);

            //return tickets.GetXml("Tickets", "Ticket", command.Filters["TicketTypeID"] != null, command.Filters);
            return(xml);
        }
예제 #5
0
        public static string GetCustomerTickets(RestCommand command)
        {
            TicketsView tickets = new TicketsView(command.LoginUser);
            string      xml     = "";

            if (command.Filters["TicketTypeID"] != null)
            {
                try
                {
                    int        ticketTypeID = int.Parse(command.Filters["TicketTypeID"]);
                    TicketType ticketType   = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                    if (ticketType.OrganizationID != command.Organization.ParentID)
                    {
                        throw new Exception();
                    }
                    tickets.LoadByCustomerTicketTypeID(command.Organization.OrganizationID, ticketTypeID);
                }
                catch (Exception ex)
                {
                    throw new RestException(HttpStatusCode.NotAcceptable, ex.Message);
                    throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                }
            }
            else
            {
                if (command.IsPaging)
                {
                    try
                    {
                        //remove Paging parameters
                        NameValueCollection filters = new NameValueCollection();

                        foreach (string key in command.Filters.AllKeys)
                        {
                            if (key.ToLower() != "pagenumber" && key.ToLower() != "pagesize")
                            {
                                filters.Add(key, command.Filters[key]);
                            }
                        }

                        tickets.LoadByCustomerID(command.Organization.OrganizationID, command.Filters, (int)command.PageNumber, (int)command.PageSize);

                        XmlTextWriter writer = Tickets.BeginXmlWrite("Tickets");

                        foreach (DataRow row in tickets.Table.Rows)
                        {
                            int  ticketId = (int)row["TicketID"];
                            Tags tags     = new Tags(command.LoginUser);
                            tags.LoadByReference(ReferenceType.Tickets, ticketId);
                            tags = tags ?? new Tags(command.LoginUser);
                            tickets.WriteXml(writer, row, "Ticket", true, new NameValueCollection(), tags);
                        }

                        int totalRecords = 0;

                        if (tickets.Count > 0)
                        {
                            totalRecords = tickets[0].TotalRecords;
                        }

                        writer.WriteElementString("TotalRecords", totalRecords.ToString());
                        xml = Tickets.EndXmlWrite(writer);
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetCustomerTickets(). Paging. SQL filtering generation failed.");
                        throw new RestException(HttpStatusCode.InternalServerError, "There was an error processing your request. Please contact TeamSupport.com", ex);
                    }
                }
                else
                {
                    tickets.LoadByCustomerID(command.Organization.OrganizationID);
                    xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters, command.IsPaging);
                    xml = AddTagsToTickets(xml, command, true);
                }
            }

            return(xml);
        }
예제 #6
0
        public static string GetTickets(RestCommand command)
        {
            string xml             = "";
            bool   hasBeenFiltered = false;
            int    totalRecords    = 0;

            if (command.IsPaging)
            {
                try
                {
                    TicketsView tickets = new TicketsView(command.LoginUser);
                    tickets.LoadAllTicketIds(command.Organization.OrganizationID, command.Filters, command.PageNumber, command.PageSize);
                    hasBeenFiltered = true;
                    XmlTextWriter writer = Tickets.BeginXmlWrite("Tickets");

                    foreach (int ticketTypeId in tickets.GroupBy(g => g.TicketTypeID).Select(p => p.Key).ToList())
                    {
                        try
                        {
                            TicketsView ticketsResult = new TicketsView(command.LoginUser);
                            ticketsResult.LoadByTicketIDList(command.Organization.OrganizationID, ticketTypeId, tickets.Where(w => w.TicketTypeID == ticketTypeId).Select(p => p.TicketID).ToList());

                            foreach (DataRow row in ticketsResult.Table.Rows)
                            {
                                int  ticketId = (int)row["TicketID"];
                                Tags tags     = new Tags(command.LoginUser);
                                tags.LoadByReference(ReferenceType.Tickets, ticketId);
                                tags = tags ?? new Tags(command.LoginUser);
                                ticketsResult.WriteXml(writer, row, "Ticket", true, !hasBeenFiltered ? command.Filters : new System.Collections.Specialized.NameValueCollection(), tags);
                            }
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). Paging.");
                        }
                    }

                    if (tickets.Count > 0)
                    {
                        totalRecords = tickets[0].TotalRecords;
                    }

                    writer.WriteElementString("TotalRecords", totalRecords.ToString());
                    xml = Tickets.EndXmlWrite(writer);
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). Paging. SQL filtering generation failed.");
                    throw new RestException(HttpStatusCode.InternalServerError, "There was an error processing your request. Please contact TeamSupport.com", ex);
                }
            }
            else
            {
                //No Paging
                if (command.Filters["TicketTypeID"] != null)
                {
                    try
                    {
                        TicketsView tickets      = new TicketsView(command.LoginUser);
                        int         ticketTypeID = int.Parse(command.Filters["TicketTypeID"]);
                        TicketType  ticketType   = TicketTypes.GetTicketType(command.LoginUser, ticketTypeID);
                        if (ticketType.OrganizationID != command.Organization.OrganizationID)
                        {
                            throw new Exception();
                        }

                        try
                        {
                            tickets.LoadByTicketTypeID(ticketTypeID, command.Organization.OrganizationID, command.Filters);
                        }
                        catch (Exception ex)
                        {
                            //if something fails use the old method
                            tickets.LoadByTicketTypeID(ticketTypeID);
                            ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). No Paging. SQL filtering generation failed, fell into old method.");
                        }

                        xml = tickets.GetXml("Tickets", "Ticket", true, command.Filters);
                        xml = AddTagsToTickets(xml, command);
                    }
                    catch (Exception ex)
                    {
                        throw new RestException(HttpStatusCode.NotAcceptable, "Invalid TicketTypeID to filter.", ex);
                    }
                }
                else
                {
                    TicketTypes ticketTypes = new TicketTypes(command.LoginUser);
                    ticketTypes.LoadByOrganizationID(command.Organization.OrganizationID);

                    TicketsView   tickets = new TicketsView(command.LoginUser);
                    XmlTextWriter writer  = Tickets.BeginXmlWrite("Tickets");

                    foreach (TicketType ticketType in ticketTypes)
                    {
                        try
                        {
                            tickets.LoadByTicketTypeID(ticketType.TicketTypeID, command.Organization.OrganizationID, command.Filters);
                        }
                        catch (Exception ex)
                        {
                            if (ex is System.Data.SqlClient.SqlException && ex.Message.ToLower().Contains("variable names must be unique within a query batch or stored procedure"))
                            {
                                throw ex;
                            }
                            else
                            {
                                //if something fails use the old method
                                tickets.LoadByTicketTypeID(ticketType.TicketTypeID);
                                ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestTickets. GetTickets(). No Paging. No TicketTypeId filter. SQL filtering generation failed, fell into old method.");
                            }
                        }

                        foreach (DataRow row in tickets.Table.Rows)
                        {
                            int  ticketId = (int)row["TicketID"];
                            Tags tags     = new Tags(command.LoginUser);
                            tags.LoadByReference(ReferenceType.Tickets, ticketId);
                            tags = tags ?? new Tags(command.LoginUser);
                            tickets.WriteXml(writer, row, "Ticket", true, command.Filters, tags);
                        }
                    }

                    xml = Tickets.EndXmlWrite(writer);
                }
            }

            return(xml);
        }