public XDocument GetPermissionProfiles() { XDocument xml = XDocument.Parse("<root></root>"); ICollection <Configuration> profiles = ConfigurationMapper.Instance.GetConfiguration(SessionManager.User, "permissions.profiles.*"); foreach (Configuration conf in profiles) { XElement profile = new XElement("permissionProfile"); profile.Add(new XAttribute("id", conf.Key.Substring(21))); profile.Add(new XAttribute("label", BusinessObjectHelper.GetXmlLabelInUserLanguage(conf.Value.Element("labels")).Value)); xml.Root.Add(profile); } return(xml); }
/// <summary> /// Gets the templates of all document types. /// </summary> /// <returns>Templates list.</returns> public XDocument GetTemplates() { XDocument xml = XDocument.Parse("<root><warehouseDocument/><salesDocument/><purchaseDocument/><orderDocument/><financialDocument/><salesOrderDocument/><item/><contractor/><serviceDocument/><complaintDocument/><inventoryDocument/><technologyDocument/><productionOrderDocument/></root>"); BusinessObjectType[] types = new BusinessObjectType[] { BusinessObjectType.WarehouseDocument, BusinessObjectType.CommercialDocument, BusinessObjectType.FinancialDocument, BusinessObjectType.Item, BusinessObjectType.Contractor, BusinessObjectType.ServiceDocument, BusinessObjectType.ComplaintDocument, BusinessObjectType.InventoryDocument }; DictionaryMapper.Instance.CheckForChanges(); foreach (BusinessObjectType type in types) { if (!ConfigurationMapper.Instance.Templates.ContainsKey(type)) { continue; } foreach (string templateName in ConfigurationMapper.Instance.Templates[type].Keys) { XElement fullTemplate = ConfigurationMapper.Instance.Templates[type][templateName]; if (fullTemplate.Element("visible") != null && fullTemplate.Element("visible").Value.ToUpperInvariant() == "FALSE") { continue; } XElement labelsElement = fullTemplate.Element("labels"); string Lang = fullTemplate.Element("labels").Elements().Aggregate("", (b, node) => b += ";" + node.Value.ToString()); XElement template = new XElement("template", new XAttribute("id", templateName), new XAttribute("label", BusinessObjectHelper.GetXmlLabelInUserLanguage(fullTemplate.Element("labels")).Value), new XAttribute("labelEn", Lang), //preferredLang.FirstOrDefault().ToString() new XAttribute("icon", fullTemplate.Element("icon").Value)); if (fullTemplate.Element("isDefault") != null && fullTemplate.Element("isDefault").Value.ToUpperInvariant() == "TRUE") { template.Add(new XAttribute("isDefault", "true")); } DocumentCategory?dc = null; XElement documentTypeIdElement = ((XElement)fullTemplate.FirstNode).Element("documentTypeId"); if (documentTypeIdElement != null) { template.Add(new XAttribute("documentTypeId", documentTypeIdElement.Value)); Guid documentTypeId = new Guid(documentTypeIdElement.Value); DocumentType dt = DictionaryMapper.Instance.GetDocumentType(documentTypeId); if (dt == null) { throw new ArgumentException(String.Format("Invalid documentTypeId: {0} in template: {1}", documentTypeId.ToUpperString(), templateName)); } dc = dt.DocumentCategory; } if (dc == DocumentCategory.Sales) { xml.Root.Element("salesDocument").Add(template); } else if (dc == DocumentCategory.Purchase) { xml.Root.Element("purchaseDocument").Add(template); } else if (dc == DocumentCategory.Warehouse) { xml.Root.Element("warehouseDocument").Add(template); } else if (dc == DocumentCategory.Order || dc == DocumentCategory.Reservation) { xml.Root.Element("orderDocument").Add(template); } else if (dc == DocumentCategory.Financial) { xml.Root.Element("financialDocument").Add(template); } else if (dc == DocumentCategory.Service) { xml.Root.Element("serviceDocument").Add(template); } else if (dc == DocumentCategory.Complaint) { xml.Root.Element("complaintDocument").Add(template); } else if (dc == DocumentCategory.Inventory) { xml.Root.Element("inventoryDocument").Add(template); } else if (dc == DocumentCategory.SalesOrder) { xml.Root.Element("salesOrderDocument").Add(template); } else if (dc == DocumentCategory.Technology) { xml.Root.Element("technologyDocument").Add(template); } else if (dc == DocumentCategory.ProductionOrder) { xml.Root.Element("productionOrderDocument").Add(template); } else if (dc == null) { xml.Root.Element(type.ToString().Decapitalize()).Add(template); } } } return(xml); }