public static string GetCRMLinkTableItem(RestCommand command, int cRMLinkID) { CRMLinkTableItem cRMLinkTableItem = CRMLinkTable.GetCRMLinkTableItem(command.LoginUser, cRMLinkID); if (cRMLinkTableItem.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(cRMLinkTableItem.GetXml("CRMLinkTableItem", true)); }
public static void ForceCRMResync() { CRMLinkTable crmLinkTable = new CRMLinkTable(UserSession.LoginUser); crmLinkTable.LoadByOrganizationID(UserSession.LoginUser.OrganizationID); if (!crmLinkTable.IsEmpty) { crmLinkTable[0].LastProcessed = new DateTime(1900, 1, 1); crmLinkTable[0].LastLink = new DateTime(1980, 1, 1); crmLinkTable.Save(); } }
public static string GetCRMLinkTable(RestCommand command) { CRMLinkTable cRMLinkTable = new CRMLinkTable(command.LoginUser); cRMLinkTable.LoadByOrganizationID(command.Organization.OrganizationID); if (command.Format == RestFormat.XML) { return(cRMLinkTable.GetXml("CRMLinkTable", "CRMLinkTableItem", true, command.Filters)); } else { throw new RestException(HttpStatusCode.BadRequest, "Invalid data format"); } }
public ReportFieldItem[] GetFields(int reportSubCatID) { LoginUser loginUser = TSAuthentication.GetLoginUser(); List <ReportFieldItem> result = new List <ReportFieldItem>(); TicketTypes ticketTypes = new TicketTypes(loginUser); ticketTypes.LoadAllPositions(loginUser.OrganizationID); ReportSubcategory subCat = ReportSubcategories.GetReportSubcategory(loginUser, reportSubCatID); ReportTable primaryTable = ReportTables.GetReportTable(loginUser, subCat.ReportCategoryTableID); ReportTableFields reportTableFields = new ReportTableFields(loginUser); reportTableFields.LoadByReportTableID(subCat.ReportCategoryTableID); CRMLinkTable crmLink = new CRMLinkTable(loginUser); crmLink.LoadByOrganizationID(loginUser.OrganizationID); bool isJiraActive = crmLink.Where(p => p.CRMType.ToLower() == "jira" && p.Active).Any(); List <string> jiraFields = new List <string>() { "DateModifiedByJiraSync", "JiraID", "SyncWithJira", "JiraKey", "JiraLinkURL", "JiraStatus" }; foreach (ReportTableField reportTableField in reportTableFields) { if ((isJiraActive && jiraFields.Where(p => p == reportTableField.FieldName).Any() || !jiraFields.Where(p => p == reportTableField.FieldName).Any())) { result.Add(new ReportFieldItem(primaryTable.Alias, true, reportTableField)); } } if (primaryTable.CustomFieldRefType != ReferenceType.None) { CustomFields customFields = new CustomFields(loginUser); customFields.LoadByReferenceType(loginUser.OrganizationID, primaryTable.CustomFieldRefType, null, "Name"); foreach (CustomField customField in customFields) { if (customField.RefType == ReferenceType.Tickets || customField.RefType == ReferenceType.Actions) { TicketType ticketType = ticketTypes.FindByTicketTypeID(customField.AuxID); if (ticketType != null) { result.Add(new ReportFieldItem(primaryTable.Alias, true, customField, ticketType.Name)); } } else { result.Add(new ReportFieldItem(primaryTable.Alias, true, customField, "")); } } } if (subCat.ReportTableID != null) { ReportTable subTable = ReportTables.GetReportTable(loginUser, (int)subCat.ReportTableID); reportTableFields = new ReportTableFields(loginUser); reportTableFields.LoadByReportTableID((int)subCat.ReportTableID); foreach (ReportTableField reportTableField in reportTableFields) { result.Add(new ReportFieldItem(subTable.Alias, false, reportTableField)); } if (subTable.CustomFieldRefType != ReferenceType.None) { CustomFields customFields = new CustomFields(loginUser); customFields.LoadByReferenceType(loginUser.OrganizationID, subTable.CustomFieldRefType, null, "Name"); foreach (CustomField customField in customFields) { if (customField.RefType == ReferenceType.Tickets || customField.RefType == ReferenceType.Actions) { TicketType ticketType = ticketTypes.FindByTicketTypeID(customField.AuxID); if (ticketType != null) { result.Add(new ReportFieldItem(subTable.Alias, false, customField, ticketType.Name)); } } else { result.Add(new ReportFieldItem(subTable.Alias, false, customField, "")); } } } } return(result.ToArray()); }
/// <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)); } }