/// <summary> /// Gets xml containing full data of all own companies. /// </summary> /// <returns>Xml containing full data of own companies.</returns> public XDocument GetOwnCompanies() { XDocument xml = this.ExecuteStoredProcedure(StoredProcedure.contractor_p_getOwnCompanies, true, null); ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>(); XDocument retXml = XDocument.Parse("<root />"); var ownCompaniesId = from entry in xml.Root.Element("contractor").Elements() where entry.Element("isOwnCompany").Value == "1" select new Guid(entry.Element("id").Value); foreach (Guid id in ownCompaniesId) { XElement contractorElement = contractorMapper.ConvertDBToBoXmlFormat(xml, id).Root.Element("contractor"); retXml.Root.Add(contractorElement); } return(retXml); }
private void ConvertShiftTransactionFromDbToBoXmlFormat(XDocument xml, Guid id, XElement convertedST) { string strId = id.ToUpperString(); XElement shiftTransactionElement = xml.Root.Element("shiftTransaction").Elements().Where(x => x.Element("id").Value == strId).FirstOrDefault(); if (shiftTransactionElement == null) { throw new InvalidOperationException("No ShiftTransaction found to convert."); } foreach (XElement column in shiftTransactionElement.Elements()) { if (column.Name.LocalName != "applicationUserId") { convertedST.Add(column); //auto-cloning } else { ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>(); XDocument contractorXml = contractorMapper.ConvertDBToBoXmlFormat(xml, new Guid(column.Value)); convertedST.Add(new XElement("user", contractorXml.Root.Element("contractor"))); } } //convert shifts XElement shifts = new XElement("shifts"); convertedST.Add(shifts); foreach (XElement shift in xml.Root.Element("shift").Elements().Where(s => s.Element("shiftTransactionId").Value == strId)) { XElement newShift = new XElement("shift", shift.Elements()); shifts.Add(newShift); XElement shiftAttributes = new XElement("attributes"); newShift.Add(shiftAttributes); var attribs = xml.Root.Element("shiftAttrValue").Elements().Where(e => e.Element("shiftId").Value == newShift.Element("id").Value); foreach (XElement attrEntry in attribs) { XElement attribute = new XElement("attribute"); shiftAttributes.Add(attribute); foreach (XElement attrElement in attrEntry.Elements()) { if (!VariableColumnName.IsVariableColumnName(attrElement.Name.LocalName)) { attribute.Add(attrElement); //auto-cloning } else { ShiftField cf = DictionaryMapper.Instance.GetShiftField(new Guid(attrEntry.Element(XmlName.ShiftFieldId).Value)); string dataType = cf.Metadata.Element(XmlName.DataType).Value; if (dataType != DataType.Xml) { attribute.Add(new XElement(XmlName.Value, BusinessObjectHelper.ConvertAttributeValueForSpecifiedDataType(attrElement.Value, dataType))); } else { attribute.Add(new XElement(XmlName.Value, attrElement.Elements())); } } } } } //convert container shifts XElement containerShifts = new XElement("containerShifts"); convertedST.Add(containerShifts); foreach (XElement containerShift in xml.Root.Element("containerShift").Elements().Where(s => s.Element("shiftTransactionId").Value == strId)) { shifts.Add(new XElement("containerShift", containerShift.Elements())); } }