Esempio n. 1
0
        public static IWriteableStore SaveItem(this IWriteableStore store, IHasId obj)
        {
            if (store == null)
            {
                return(store);
            }

            store.Commit(CommitBag.New().MarkItemSaved(obj));
            return(store);
        }
Esempio n. 2
0
        public static IWriteableStore DeleteItems(this IWriteableStore store, params StoredObjectId[] objs)
        {
            if (store == null)
            {
                return(store);
            }

            var commitBag = CommitBag.New();

            commitBag.MarkItemsDeleted(objs.ToList());
            store.Commit(commitBag);
            return(store);
        }
Esempio n. 3
0
        /// <summary>
        /// Modifies the id of an object in a store
        /// </summary>
        /// <param name="store"></param>
        /// <param name="idToChange"></param>
        /// <param name="newId"></param>
        public static void ChangeStoredObjectId(this IStore store, StoredObjectId idToChange, object newId)
        {
            if (store == null)
            {
                return;
            }

            if (idToChange == null)
            {
                return;
            }

            //if we're not changing anything, skip
            if (idToChange.ObjectId.Equals(newId))
            {
                return;
            }

            //get the object to ensure it exists
            var obj = store.Get(idToChange);

            if (obj == null)
            {
                return;
            }

            //mark delete
            var cb = CommitBag.New();

            cb.MarkItemDeleted(idToChange);

            //change the id
            if (obj is IHasSettableId)
            {
                IHasSettableId ihs = obj as IHasSettableId;
                ihs.SetId(newId);
            }
            else
            {
                PropertyInfo pi = obj.GetType().GetProperty("Id", BindingFlags.Public | BindingFlags.Instance);
                pi.SetValue(obj, newId);
            }
            //mark save new item and commit
            cb.MarkItemSaved(obj);
            store.Commit(cb);
        }