public static string GetEmailTemplateTable(RestCommand command, int emailTemplateTableID) { EmailTemplateTable emailTemplateTable = EmailTemplateTables.GetEmailTemplateTable(command.LoginUser, emailTemplateTableID); if (emailTemplateTable.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(emailTemplateTable.GetXml("EmailTemplateTable", true)); }
public static string GetEmailTemplateTables(RestCommand command) { EmailTemplateTables emailTemplateTables = new EmailTemplateTables(command.LoginUser); emailTemplateTables.LoadByOrganizationID(command.Organization.OrganizationID); if (command.Format == RestFormat.XML) { return(emailTemplateTables.GetXml("EmailTemplateTables", "EmailTemplateTable", true, command.Filters)); } else { throw new RestException(HttpStatusCode.BadRequest, "Invalid data format"); } }
public static PlaceHolders[] GetPlaceHolders(int emailTemplateID) { EmailTemplate template = EmailTemplates.GetEmailTemplate(UserSession.LoginUser, emailTemplateID); List <PlaceHolders> result = new List <PlaceHolders>(); EmailTemplateParameters paramaters = new EmailTemplateParameters(UserSession.LoginUser); paramaters.LoadByTemplate(emailTemplateID); List <PlaceHolder> list = new List <PlaceHolder>(); PlaceHolders phs = new PlaceHolders(); if (!paramaters.IsEmpty) { phs.Name = "Miscellaneous"; phs.Description = ""; foreach (EmailTemplateParameter parameter in paramaters) { PlaceHolder ph = new PlaceHolder(); ph.Name = parameter.Name; ph.Description = parameter.Description ?? ""; list.Add(ph); } PlaceHolder phTo = new PlaceHolder(); phTo.Name = "ToEmailAddress"; phTo.Description = "This adds the recipient's email address."; list.Add(phTo); phTo = new PlaceHolder(); phTo.Name = "ToFirstName"; phTo.Description = "This adds the recipient's first name."; list.Add(phTo); phTo = new PlaceHolder(); phTo.Name = "ToLastName"; phTo.Description = "This adds the recipient's last name."; list.Add(phTo); phs.Items = list.ToArray(); result.Add(phs); } EmailTemplateTables tables = new EmailTemplateTables(UserSession.LoginUser); tables.LoadByTemplate(emailTemplateID); foreach (EmailTemplateTable table in tables) { phs = new PlaceHolders(); phs.Name = table.Alias; phs.Description = table.Description ?? ""; list.Clear(); ReportTable reportTable = ReportTables.GetReportTable(UserSession.LoginUser, table.ReportTableID); ReportTableFields fields = new ReportTableFields(UserSession.LoginUser); fields.LoadByReportTableID(table.ReportTableID); foreach (ReportTableField field in fields) { PlaceHolder ph = new PlaceHolder(); ph.Name = table.Alias + '.' + field.FieldName; ph.Description = field.Description ?? ""; list.Add(ph); } //do custom fields here ReferenceType refType = reportTable.CustomFieldRefType; if (refType != ReferenceType.None) { //TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser); //ticketTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID); CustomFields customFields = new CustomFields(UserSession.LoginUser); customFields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, refType, null, "Name"); foreach (CustomField customField in customFields) { string customFieldName = table.Alias + "." + customField.Name; bool flag = false; foreach (PlaceHolder existingPH in list) { if (existingPH.Name == customFieldName) { flag = true; break; } } if (flag) { continue; } PlaceHolder ph = new PlaceHolder(); ph.Name = customFieldName; ph.Description = ""; list.Add(ph); /* * if (customField.RefType == ReferenceType.Tickets || customField.RefType == ReferenceType.Actions) * { * TicketType ticketType = ticketTypes.FindByTicketTypeID(customField.AuxID); * if (ticketType != null) * { * // * } * } * else * { * }*/ } } phs.Items = list.ToArray(); result.Add(phs); } phs = new PlaceHolders(); phs.Name = "MyCompany"; phs.Description = "Your company's information"; list.Clear(); ReportTableFields companyFields = new ReportTableFields(UserSession.LoginUser); companyFields.LoadByReportTableID(6); foreach (ReportTableField field in companyFields) { PlaceHolder ph = new PlaceHolder(); ph.Name = "MyCompany." + field.FieldName; ph.Description = field.Description ?? ""; list.Add(ph); } phs.Items = list.ToArray(); result.Add(phs); return(result.ToArray()); }