Exemple #1
0
        public void AddTicketTag(int tagID, int ticketID)
        {
            Tag    tag    = Tags.GetTag(UserSession.LoginUser, tagID);
            Ticket ticket = Tickets.GetTicket(UserSession.LoginUser, ticketID);

            if (tag.OrganizationID != UserSession.LoginUser.OrganizationID || ticket.OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return;
            }
            TagLink link = TagLinks.GetTagLink(UserSession.LoginUser, ReferenceType.Tickets, ticketID, tagID);

            if (link == null)
            {
                TagLinks links = new TagLinks(UserSession.LoginUser);
                link         = links.AddNewTagLink();
                link.RefType = ReferenceType.Tickets;
                link.RefID   = ticketID;
                link.TagID   = tagID;
                links.Save();
            }
        }
Exemple #2
0
        /// <summary>
        /// Update the Ticket related fields that live in their own table.
        /// </summary>
        /// <param name="command">Command received in the request to read and process the data in the request body.</param>
        /// <param name="ticketId">TicketId to update its record.</param>
        private static void UpdateFieldsOfSeparateTable(RestCommand command, Ticket ticket, bool isCustomerTicket = false)
        {
            try
            {
                //Add as necessary to the list and then to the switch-case below for the work to update it.
                List <string> fields = new List <string>()
                {
                    "jirakey", "tags"
                };

                foreach (string field in fields.Select(p => p.ToLower()).ToList())
                {
                    XmlNode node = GetNode(command, field);

                    if (node != null)
                    {
                        switch (field)
                        {
                        case "jirakey":
                            string           jiraKey          = node.InnerText;
                            TicketLinkToJira ticketLinkToJira = new TicketLinkToJira(command.LoginUser);
                            ticketLinkToJira.LoadByTicketID(ticket.TicketID);
                            int?crmLinkId = null;

                            //Next line and 2 If statements are the same as in \webapp\app_code\ticketservice.cs SetSyncWithJira(). Might need to consider making a common funcion for both
                            crmLinkId = CRMLinkTable.GetIdBy(ticket.OrganizationID, IntegrationType.Jira.ToString().ToLower(), ticket.ProductID, command.LoginUser);

                            //If product is not associated to an instance then get the 'default' instance
                            if (crmLinkId == null || crmLinkId <= 0)
                            {
                                CRMLinkTable crmlink = new CRMLinkTable(command.LoginUser);
                                crmlink.LoadByOrganizationID(ticket.OrganizationID);

                                crmLinkId = crmlink.Where(p => p.InstanceName == "Default" &&
                                                          p.CRMType.ToLower() == IntegrationType.Jira.ToString().ToLower())
                                            .Select(p => p.CRMLinkID).FirstOrDefault();
                            }

                            if (ticketLinkToJira != null && ticketLinkToJira.Any())
                            {
                                string oldJiraKey = ticketLinkToJira[0].JiraKey;
                                ticketLinkToJira[0].JiraKey   = jiraKey.ToLower() == "newjiraissue" ? null : jiraKey;
                                ticketLinkToJira[0].CrmLinkID = crmLinkId;
                                ticketLinkToJira.Save();
                                ActionLogs.AddActionLog(command.LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, string.Format("Changed JiraKey from '{0}' to '{1}'.", oldJiraKey, jiraKey));
                            }
                            else
                            {
                                TicketLinkToJiraItem newJiraLink = ticketLinkToJira.AddNewTicketLinkToJiraItem();
                                newJiraLink.TicketID     = ticket.TicketID;
                                newJiraLink.SyncWithJira = true;
                                newJiraLink.JiraID       = null;
                                newJiraLink.JiraKey      = jiraKey.ToLower() == "newjiraissue" ? null : jiraKey;
                                newJiraLink.JiraLinkURL  = null;
                                newJiraLink.JiraStatus   = null;
                                newJiraLink.CreatorID    = command.LoginUser.UserID;
                                newJiraLink.CrmLinkID    = crmLinkId;

                                if (newJiraLink.CrmLinkID != null && newJiraLink.CrmLinkID > 0)
                                {
                                    newJiraLink.Collection.Save();
                                    ActionLogs.AddActionLog(command.LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, string.Format("Linked to JiraKey '{0}'.", jiraKey));
                                }
                            }
                            break;

                        case "tags":
                            TagLinks currentTagLinks = new TagLinks(command.LoginUser);
                            currentTagLinks.LoadByReference(ReferenceType.Tickets, ticket.TicketID);
                            XmlNodeList nodeList = node.ChildNodes;
                            List <int>  newTags  = new List <int>();

                            foreach (XmlNode tagNode in nodeList)
                            {
                                string tagValue = tagNode["Value"].InnerText;

                                Tag newTag = Tags.GetTag(command.LoginUser, tagValue);

                                if (newTag == null)
                                {
                                    Tags tag = new Tags(command.LoginUser);
                                    newTag = tag.AddNewTag();
                                    newTag.OrganizationID = isCustomerTicket ? command.Organization.ParentID ?? command.Organization.OrganizationID : command.Organization.OrganizationID;
                                    newTag.Value          = tagValue;
                                    tag.Save();
                                }

                                newTags.Add(newTag.TagID);
                            }

                            foreach (int tag in newTags)
                            {
                                TagLink newTagLink = currentTagLinks.Where(p => p.TagID == tag && p.RefID == ticket.TicketID).SingleOrDefault();
                                if (newTagLink == null)
                                {
                                    TagLinks tagLink = new TagLinks(command.LoginUser);
                                    newTagLink         = tagLink.AddNewTagLink();
                                    newTagLink.TagID   = tag;
                                    newTagLink.RefType = ReferenceType.Tickets;
                                    newTagLink.RefID   = ticket.TicketID;
                                    tagLink.Save();
                                }
                            }

                            List <TagLink> deleteTagLinks = currentTagLinks.Where(p => !newTags.Contains(p.TagID)).ToList();

                            foreach (TagLink deleteTagLink in deleteTagLinks)
                            {
                                deleteTagLink.Delete();
                                deleteTagLink.Collection.Save();
                            }

                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            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));
            }
        }