コード例 #1
0
        public static string GetContactsView(RestCommand command)
        {
            ContactsView contactsView = new ContactsView(command.LoginUser);

            contactsView.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(contactsView.GetXml("ContactsView", "ContactsViewItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
コード例 #2
0
        public static string GetItems(RestCommand command, int organizationID, bool orderByDateCreated = false)
        {
            if (Organizations.GetOrganization(command.LoginUser, organizationID).ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ContactsView items = new ContactsView(command.LoginUser);

            if (orderByDateCreated)
            {
                items.LoadByOrganizationID(organizationID, "DateCreated DESC");
            }
            else
            {
                items.LoadByOrganizationID(organizationID);
            }
            return(items.GetXml("Contacts", "Contact", true, command.Filters));
        }
コード例 #3
0
        public static string GetTicketContacts(RestCommand command, int ticketIDOrNumber, bool orderByDateCreated = false)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ContactsView contacts = new ContactsView(command.LoginUser);

            if (orderByDateCreated)
            {
                contacts.LoadByTicketID(ticket.TicketID, "ut.DateCreated DESC");
            }
            else
            {
                contacts.LoadByTicketID(ticket.TicketID);
            }
            return(contacts.GetXml("Contacts", "Contact", true, command.Filters));
        }
コード例 #4
0
        public static string GetItems(RestCommand command, bool orderByDateCreated = false, int?limitNumber = null, bool isCustomer = false)
        {
            ContactsView items     = new ContactsView(command.LoginUser);
            string       xmlString = string.Empty;

            try
            {
                if (orderByDateCreated)
                {
                    //This seems to be Zapier only
                    items.LoadByParentOrganizationID(command.Organization.OrganizationID, command.Filters, null, null, "DateCreated DESC", limitNumber, isCustomer);
                }
                else
                {
                    items.LoadByParentOrganizationID(command.Organization.OrganizationID, command.Filters, command.PageNumber, command.PageSize, isCustomer: isCustomer);
                }

                //SQL filtering was done already, there's no need for .NET filtering thus the empty collection for the last parameter
                xmlString = items.GetXml("Contacts", "Contact", true, new System.Collections.Specialized.NameValueCollection(), command.IsPaging);
            }
            catch (Exception ex)
            {
                //if something fails use the old method. This one does not have paging.
                //Something went wrong with the sql filtering and an exception was thrown and caught, .NET filtering will need to be done
                items = new ContactsView(command.LoginUser);

                if (orderByDateCreated)
                {
                    items.LoadByParentOrganizationID(command.Organization.OrganizationID, "DateCreated DESC", limitNumber);
                }
                else
                {
                    items.LoadByParentOrganizationID(command.Organization.OrganizationID);
                }

                xmlString = items.GetXml("Contacts", "Contact", true, command.Filters);
                ExceptionLogs.LogException(command.LoginUser, ex, "API", "RestContacts. GetItems(). SQL filtering generation failed, fell into old method.");
            }

            return(xmlString);
        }