예제 #1
0
        /// <summary>
        /// Converts a <see cref="BusinessObject"/> from its xml to <see cref="BusinessObject"/> form.
        /// </summary>
        /// <param name="objectXml">Xml rootElement containing <see cref="IBusinessObject"/>.</param>
        /// <param name="options">Xml containing options for the object during save operation.</param>
        /// <returns>
        /// Converted <see cref="IBusinessObject"/>.
        /// </returns>
        public override IBusinessObject ConvertToBusinessObject(XElement objectXml, XElement options)
        {
            CustomBusinessObject list = new CustomBusinessObject(new XElement(objectXml));

            if (objectXml.Element("id") != null)
            {
                list.Id      = new Guid(objectXml.Element("id").Value);
                list.Version = list.Id;
            }

            return(list);
        }
예제 #2
0
        /// <summary>
        /// Creates the item equivalent group using specified xml item list.
        /// </summary>
        /// <param name="requestXml">Client's request containing list of items to bind into one equivalent group.</param>
        public void CreateItemEquivalentGroup(string requestXml)
        {
            XDocument xml = XDocument.Parse(requestXml);

            SessionManager.VolatileElements.ClientRequest = xml;

            Item[] items = new Item[xml.Root.Elements().Count()];
            int    i     = 0;

            foreach (XElement element in xml.Root.Elements())
            {
                IBusinessObject bo = this.Mapper.LoadBusinessObject(BusinessObjectType.Item, new Guid(element.Attribute("id").Value));

                items[i++] = (Item)bo;
            }

            //check if any item is already in other equivalent group
            List <Item> alreadyRelatedItems = new List <Item>();
            Guid?       itemEqGrpId         = null;

            foreach (Item item in items)
            {
                foreach (ItemRelation relation in item.Relations.Children)
                {
                    if (relation.ItemRelationTypeName == ItemRelationTypeName.Item_EquivalentGroup)
                    {
                        if (itemEqGrpId == null)
                        {
                            itemEqGrpId = new Guid(((CustomBusinessObject)relation.RelatedObject).Value.Element("id").Value);
                        }
                        else if (itemEqGrpId != new Guid(((CustomBusinessObject)relation.RelatedObject).Value.Element("id").Value))
                        {
                            throw new ClientException(ClientExceptionId.ItemEquivalentGroupException, null, "itemName:" + item.Name);
                        }

                        alreadyRelatedItems.Add(item);
                    }
                }
            }

            if (itemEqGrpId == null)
            {
                itemEqGrpId = Guid.NewGuid();
            }

            foreach (Item item in items)
            {
                if (!alreadyRelatedItems.Contains(item))
                {
                    ItemRelation rel = item.Relations.CreateNew();
                    rel.ItemRelationTypeName = ItemRelationTypeName.Item_EquivalentGroup;
                    CustomBusinessObject bo = CustomBusinessObject.CreateEmpty();

                    bo.Id = itemEqGrpId;
                    bo.Value.Add(new XElement("id", itemEqGrpId.ToUpperString()));

                    rel.RelatedObject = bo;
                }
            }

            this.SaveBusinessObjects(items);
        }