예제 #1
0
        public static string UnSubscribeFromTicket(RestCommand command, int ticketIDOrNumber, int userId)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

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

            Subscriptions.RemoveSubscription(command.LoginUser, userId, ReferenceType.Tickets, ticket.TicketID);

            return(ticket.GetXml("Ticket", true));
        }
예제 #2
0
        public static string DeleteTicket(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticketViewItem = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);
            Ticket          ticket         = Tickets.GetTicket(command.LoginUser, ticketViewItem.TicketID);
            string          result         = ticketViewItem.GetXml("Ticket", true);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ticket.Delete();
            ticket.Collection.Save();
            return(result);
        }
        public static string CreateAttachment(RestCommand command, int ticketIDOrNumber, int actionID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            string path = AttachmentPath.GetPath(command.LoginUser, command.Organization.OrganizationID, AttachmentPath.Folder.Actions, 3);

            path = Path.Combine(path, actionID.ToString());
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            HttpFileCollection files = command.Context.Request.Files;

            if (files.Count > 0)
            {
                if (files[0].ContentLength > 0)
                {
                    string fileName = RemoveSpecialCharacters(DataUtils.VerifyUniqueUrlFileName(path, Path.GetFileName(files[0].FileName)));

                    files[0].SaveAs(Path.Combine(path, fileName));

                    Attachment attachment = (new Attachments(command.LoginUser)).AddNewAttachment();
                    attachment.RefType        = AttachmentProxy.References.Actions;
                    attachment.RefID          = (int)actionID;
                    attachment.OrganizationID = command.Organization.OrganizationID;
                    attachment.FileName       = fileName;
                    attachment.Path           = Path.Combine(path, fileName);
                    attachment.FileType       = files[0].ContentType;
                    attachment.FileSize       = files[0].ContentLength;
                    attachment.FilePathID     = 3;
                    attachment.Collection.Save();
                    return(attachment.Collection.GetXml("Attachments", "Attachment", true, command.Filters));
                }
                else
                {
                    throw new RestException(HttpStatusCode.BadRequest, "The file to attach is empty.");
                }
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "No file to attach.");
            }
        }
예제 #4
0
        public static string GetTicket(RestCommand command, int ticketID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketID);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tags tags = new Tags(command.LoginUser);

            tags.LoadByReference(ReferenceType.Tickets, ticket.TicketID);
            string ticketXmlString = ticket.GetXml("Ticket", true, tags);

            return(ticketXmlString);
        }
예제 #5
0
        public static string GetActions(RestCommand command, int ticketIDOrNumber, int?limitNumber = null)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ActionsView actions = new ActionsView(command.LoginUser);

            actions.LoadByTicketID(ticket.TicketID, limitNumber);

            actions.Select(p => { p.Description = RemoveInvalidXmlChars(p.Description); return(p); }).ToList();

            return(actions.GetXml("Actions", "Action", true, command.Filters));
        }
예제 #6
0
        public static string UpdateTicket(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticketViewItem = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);
            Ticket          ticket         = Tickets.GetTicket(command.LoginUser, ticketViewItem.TicketID);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            ticket.ReadFromXml(command.Data, false);
            ticket.Collection.Save();
            ticket.UpdateCustomFieldsFromXml(command.Data);

            ticket = Tickets.GetTicket(command.LoginUser, ticket.TicketID);
            UpdateFieldsOfSeparateTable(command, ticket);

            return(TicketsView.GetTicketsViewItem(command.LoginUser, ticket.TicketID).GetXml("Ticket", true));
        }
예제 #7
0
        public static string CreateAction(RestCommand command, int ticketIDOrNumber)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Actions actions = new Actions(command.LoginUser);

            TeamSupport.Data.Action action = actions.AddNewAction();
            action.TicketID = ticket.TicketID;
            action.ReadFromXml(command.Data, true);
            action.Collection.Save();
            action.UpdateCustomFieldsFromXml(command.Data);
            return(ActionsView.GetActionsViewItem(command.LoginUser, action.ActionID).GetXml("Action", true));
        }
        public static string RemoveTicketOrganization(RestCommand command, int ticketIDOrNumber, int organizationID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Organization organization = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (organization == null || organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tickets tickets = new Tickets(command.LoginUser);

            tickets.RemoveOrganization(organizationID, ticket.TicketID);
            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organizationID).GetXml("Customer", true));
        }
        public static string GetTicketOrganizations(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);
            }
            OrganizationsView organizations = new OrganizationsView(command.LoginUser);

            if (orderByDateCreated)
            {
                organizations.LoadByTicketID(ticket.TicketID, "ot.DateCreated DESC");
            }
            else
            {
                organizations.LoadByTicketID(ticket.TicketID);
            }
            return(organizations.GetXml("Customers", "Customer", true, command.Filters));
        }
예제 #10
0
        public static string RemoveTicketContact(RestCommand command, int ticketIDOrNumber, int contactID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            User         user         = Users.GetUser(command.LoginUser, contactID);
            Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID);

            if (organization == null || organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Tickets tickets = new Tickets(command.LoginUser);

            tickets.RemoveContact(user.UserID, ticket.TicketID);
            return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true));
        }