Exemple #1
0
        public override void SaveChanges(XDocument document)
        {
            if (this.Id == null)
            {
                this.GenerateId();
            }

            if (this.Status != BusinessObjectStatus.Unchanged && this.Status != BusinessObjectStatus.Unknown)
            {
                ShiftField field = DictionaryMapper.Instance.GetShiftField(this.ShiftFieldId);

                BusinessObjectHelper.SaveBusinessObjectChanges(this, document, null, field.Metadata.Element("dataType").Value);
            }
        }
Exemple #2
0
        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()));
            }
        }