Ejemplo n.º 1
0
        /// <summary>
        /// Saves changes of current <see cref="BusinessObject"/> to the operations list.
        /// </summary>
        /// <param name="document">Xml document containing operation list to execute.</param>
        public override void SaveChanges(XDocument document)
        {
            if (this.Id == null)
            {
                this.GenerateId();
            }

            if (this.Status != BusinessObjectStatus.Unchanged && this.Status != BusinessObjectStatus.Unknown)
            {
                ContractorField field = DictionaryMapper.Instance.GetContractorField(this.ContractorFieldId);
                BusinessObjectHelper.SaveBusinessObjectChanges(this, document, null, field.Metadata.Element("dataType").Value);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts ContractorAttrValue table from database xml format to <see cref="BusinessObject"/>'s xml format.
        /// </summary>
        /// <param name="xml">Full xml with all tables in database format.</param>
        /// <param name="id">Id of the main <see cref="Contractor"/>.</param>
        /// <param name="outXml">Output xml in <see cref="BusinessObject"/>'s xml format.</param>
        private void ConvertAttributesFromDbToBoXmlFormat(XDocument xml, Guid id, XDocument outXml)
        {
            if (xml.Root.Element("contractorAttrValue") != null)
            {
                XElement attributes = new XElement("attributes");
                outXml.Root.Element("contractor").Add(attributes);
                var elements = from node in xml.Root.Element("contractorAttrValue").Elements()
                               where node.Element("contractorId").Value == id.ToUpperString()
                               orderby Convert.ToInt32(node.Element("order").Value, CultureInfo.InvariantCulture) ascending
                               select node;

                foreach (XElement element in elements)
                {
                    XElement attribute = new XElement("attribute");
                    attributes.Add(attribute);

                    foreach (XElement attrElement in element.Elements())
                    {
                        if (attrElement.Name.LocalName != "contractorId")
                        {
                            if (!VariableColumnName.IsVariableColumnName(attrElement.Name.LocalName))
                            {
                                attribute.Add(attrElement); //auto-cloning
                            }
                            else
                            {
                                ContractorField cf = DictionaryMapper.Instance.GetContractorField(new Guid(element.Element("contractorFieldId").Value));

                                string dataType = cf.Metadata.Element("dataType").Value;

                                if (dataType != "xml")
                                {
                                    attribute.Add(new XElement("value", BusinessObjectHelper.ConvertAttributeValueForSpecifiedDataType(attrElement.Value, dataType)));
                                }
                                else
                                {
                                    attribute.Add(new XElement("value", attrElement.Elements()));
                                }
                            }
                        }
                    }
                }
            }
        }