public void CreateRetrieveUpdateDelete()
        {
            string sku = DateTime.Now.ToString( "MMddHHmm" );
            string name = string.Format( "test item - {0}", DateTime.Now.ToString( "MMdd HHmm" ) );

            // create test
            Item item = new Item();
            item.Sku = sku;
            item.Name = name;
            item.Save();

            // retrieve test
            item = Item.Retrieve( sku );
            Assert.AreEqual( name, item.Name );

            // update test
            item.Name += " update test";
            item.Save();

            // delete test
            item.Delete();
        }
        /// <summary>
        /// Moves an Item to a Date Format Folder. Will create the folder based off the Date if the folder does not exist.
        /// </summary>
        /// <param name="topParent">Destination Folder</param>
        /// <param name="toMove">Item that is being moved</param>
        private static void MoveItemToDateFolder(Item topParent, Item toMove)
        {
            #if NET40
            Contract.Requires(topParent.IsNotNull());
            Contract.Requires(toMove.IsNotNull());
            #else
            Assert.ArgumentNotNull(topParent, "topParent");
            Assert.ArgumentNotNull(toMove, "toMove");
            #endif

            foreach (var item in toMove.Children.ToList())
            {
                MoveItemToDateFolder(topParent, item);
            }

            if (ShouldMoveToDateFolder(toMove))
            {
                using (new EditContext(toMove, SecurityCheck.Disable))
                {
                    if (toMove.Fields["__BucketParentRef"].IsNotNull())
                    {
                        toMove.Fields["__BucketParentRef"].Value = toMove.Parent.ID.ToString();
                    }
                }

                var destinationFolder = CreateAndReturnDateFolderDestination(topParent, toMove);
                var returnValue = ItemManager.MoveItem(toMove, destinationFolder);

                // TODO: This should be handled by MoveItem. Remove this check once Logging is placed into ItemManager code.
                if (!returnValue)
                {
                    Log.Error("There has been an issue moving the item from " + toMove + " to " + destinationFolder, returnValue);
                }
            }
            else if (ShouldDeleteInCreationOfBucket(toMove))
            {
                toMove.Delete();
            }
        }
        /// <summary>
        /// Moves to recycle bin or deletes a Sitecore item.
        /// </summary>
        /// <param name="item">Sitecore item to delete.</param>
        public void DeleteItem(Item item)
        {
            if (item == null)
            {
                return;
            }

            try
            {
                using (new SecurityDisabler())
                {
                    if (Settings.RecycleBinActive)
                    {
                        item.Recycle();
                    }
                    else
                    {
                        item.Delete();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Scheduled Publish: Failed delete item {0} {1} {2}",
                    item.Paths.FullPath,
                    item.ID,
                    ex), new object());
            }
        }
Esempio n. 4
0
        public static void RemoveStatus(PlayerMobile from, Item item)
        {
            for (int i = from.Quests.Count - 1; i >= 0; i --)
            {
                BaseQuest quest = from.Quests[i];
				
                for (int j = quest.Objectives.Count - 1; j >= 0; j --)
                {
                    if (quest.Objectives[j] is ObtainObjective)
                    {
                        ObtainObjective obtain = (ObtainObjective)quest.Objectives[j];
						
                        if (obtain.Obtain != null && obtain.Obtain.IsAssignableFrom(item.GetType()))
                        {
                            obtain.CurProgress -= item.Amount;									
                            item.QuestItem = false;							
                            from.SendLocalizedMessage(1074769); // An item must be in your backpack (and not in a container within) to be toggled as a quest item. 	
                            return;					
                        }
                    }
                    else if (quest.Objectives[j] is DeliverObjective)
                    {
                        DeliverObjective deliver = (DeliverObjective)quest.Objectives[j];
						
                        if (deliver.Delivery != null && deliver.Delivery.IsAssignableFrom(item.GetType()))
                        {
                            from.SendLocalizedMessage(1074813);  // You have failed to complete your delivery.							
                            DeleteItems(from, deliver.Delivery, deliver.MaxProgress, false);						
                            deliver.Fail();
                            item.Delete();							
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 internal void RemoveProduct(Item basket, Item product)
 {
     using (new SecurityDisabler())
     {
         product.Delete();
     }
 }
 private static void DeleteMediaItemIfEmpty(BaseDataMap map, ref Item newItem, ref LevelLogger logger)
 {
     var mediaItem = (MediaItem)newItem;
     if (mediaItem != null)
     {
         if (!mediaItem.HasMediaStream(FieldNameBlog))
         {
             logger.AddInfo("Deleted Empty MediaItem Without Blob", String.Format("The media doesn't contain any Blob value (no image). To prevent an empty Media Item without a blob to remain in the Media Library, the MediaItem was deleted. Item: {0}", map.GetItemDebugInfo(newItem)));
             newItem.Delete();
             newItem = null;
             logger.IncrementCounter("DeletedEmptyMediaItem");
         }
     }
 }
        /// <summary>
        /// Deletes an item from Sitecore
        /// </summary>
        /// <returns>true if the item's database should have its template engine reloaded, false otherwise</returns>
        private bool DeleteItem(Item item, IProgressStatus progress)
        {
            bool resetFromChild = DeleteItems(item.Children, progress);
            Database db = item.Database;
            ID id = item.ID;
            string path = item.Paths.Path;

            item.Delete();

            if (EventDisabler.IsActive)
            {
                db.Caches.ItemCache.RemoveItem(id);
                db.Caches.DataCache.RemoveItemInformation(id);
            }

            progress.ReportStatus("[DELETED] {0}:{1} because it did not exist on disk".FormatWith(db.Name, path), MessageType.Warning);

            if (!resetFromChild && item.Database.Engines.TemplateEngine.IsTemplatePart(item))
            {
                return true;
            }

            return false;
        }
Esempio n. 8
0
 public static void DestoryItem(Mobile from, Item item)
 {
     Effects.PlaySound(from.Location, from.Map, 0x307);
     Effects.SendLocationEffect(from.Location, from.Map, 0x36BD, 9, 10, 0, 0);
     item.Delete();
 }
Esempio n. 9
0
 public static void Delete(Item item)
 {
     item.Delete();
 }
        /// <summary>
        /// Moves the item to a Date Format Folder. Will create the folder based off the Date if the folder does not exist.
        /// </summary>
        /// <param name="topParent">Destination Folder</param>
        /// <param name="movedItemve">The item that is being moved.</param>
        private static void MoveItemToDateFolder(Item topParent, Item movedItem)
        {
            Contract.Requires(topParent.IsNotNull());
              Contract.Requires(movedItem.IsNotNull());

              foreach (Item item in movedItem.Children.ToList())
              {
            MoveItemToDateFolder(topParent, item);
              }

              if (ShouldMoveToDateFolder(movedItem))
              {
            using (new EditContext(movedItem, SecurityCheck.Disable))
            {
              if (movedItem.Fields["__BucketParentRef"].IsNotNull())
              {
            movedItem.Fields["__BucketParentRef"].Value = movedItem.Parent.ID.ToString();
              }
            }

            Item destinationFolder = CreateAndReturnDateFolderDestination(topParent, movedItem);
            bool returnValue = ItemManager.MoveItem(movedItem, destinationFolder);

            // TODO: This should be handled by MoveItem. Remove this check once Logging is placed into ItemManager code.
            if (returnValue == false)
            {
              Log.Error("There has been an issue moving the item from " + movedItem + " to " + destinationFolder, returnValue);
            }
              }
              else if (ShouldDeleteInCreationOfBucket(movedItem))
              {
            movedItem.Delete();
              }
        }