Exemple #1
0
        /// <summary>
        /// Updates a Collection in the database with the the values provided. A new Collection is created if one does not already exist.
        /// </summary>
        /// <param name="changedCollection">The collection content to be modified.</param>
        /// <returns>The modified database collection.</returns>
        public CFCollection UpdateStoredCollection(CFCollection changedCollection)
        {
            CFCollection dbModel = new CFCollection();

            if (changedCollection.Id > 0)
            {
                dbModel = GetCollection(changedCollection.Id);
            }
            else
            {
                dbModel = CreateEntity <CFCollection>(changedCollection.EntityTypeId.Value);
            }

            //updating the "value" text elements
            dbModel.UpdateValues(changedCollection);
            dbModel.Serialize();

            if (changedCollection.Id > 0) //update Item
            {
                Db.Entry(dbModel).State = EntityState.Modified;
            }
            else
            {
                dbModel = Db.Collections.Add(dbModel);
            }

            return(dbModel);
        }
        /// <summary>
        /// Updates a Collection in the database with the the values provided. A new Collection is created if one does not already exist.
        /// </summary>
        /// <param name="changedCollection">The collection content to be modified.</param>
        /// <returns>The modified database collection.</returns>
        public CFCollection UpdateStoredCollection(CFCollection changedCollection)
        {
            CFCollection dbModel = new CFCollection();

            if (changedCollection.Id > 0)
            {
                dbModel = GetCollection(changedCollection.Id, AccessMode.Write);
            }
            else
            {
                dbModel = CreateEntity <CFCollection>(changedCollection.EntityTypeId.Value);
            }

            //updating the "value" text elements
            dbModel.UpdateValues(changedCollection);

            //update collection attribute -- issystemCollection -- Aug 21 2019
            XAttribute isSysColl = changedCollection.Data.Attribute("issystemcollection");

            if (isSysColl != null)
            {
                dbModel.Data.SetAttributeValue("issystemcollection", isSysColl.Value);
            }

            dbModel.Serialize();

            if (changedCollection.Id > 0) //update Item
            {
                Db.Entry(dbModel).State = EntityState.Modified;
            }
            else
            {
                dbModel = Db.Collections.Add(dbModel);
            }

            return(dbModel);
        }