示例#1
0
        internal async void RemoveItem(Item item)
        {
            //Add item to ItemList, remove item from CategoryItem and remove item from Category.Item on the backend


            var result = await Client.HttpClient.DeleteAsync("http://localhost:65177/api/Category/" + Category.Id.ToString() + "/Item/" + item.Id.ToString());

            if (result.IsSuccessStatusCode)
            {
                ItemList.Add((Item)item);
                CategoryItems.Remove((Item)item);
            }
        }
        public void DeleteItem(LibraryModelItem item)
        {
            XElement node =
                (from nedNodeElements in LibraryDocument.Descendants(NedNodeTag)
                 where (string)nedNodeElements.Attribute(NedNodeIdAttribute) == item.Id
                 select nedNodeElements).FirstOrDefault();

            if (node != null)
            {
                node.Remove();
            }

            if (item is CatalogueModelItem)
            {
                CatalogueItems.Remove(item as CatalogueModelItem);
                var query = from categoriesToRemove in CategoryItems where categoriesToRemove.ParentId == item.Id select categoriesToRemove;
                List <CategoryModelItem> catTempList = query.ToList <CategoryModelItem>();
                foreach (LibraryModelItem itemToRemove in catTempList)
                {
                    DeleteItem(itemToRemove);
                }
            }
            else if (item is CategoryModelItem)
            {
                CategoryItems.Remove(item as CategoryModelItem);
                foreach (LibraryModelItem miToRemove in (item as CategoryModelItem).Children())
                {
                    DeleteItem(miToRemove);
                }
            }
            else if (item is MediaItemsListModelItem)
            {
                MediaItemsListModelItem mediaItem = item as MediaItemsListModelItem;
                MediaItems.Remove(mediaItem);
                App.Engine.DeleteMediaItem(mediaItem);
            }
            else
            {
                Debug.Assert(false, FileLanguage.LibraryModel_RemovingUnknowTypeError);
            }
            App.Engine.StatisticsManager.LogItemDeleted(item.Id);
            OnLibraryItemRemoved(new LibraryRemovedEventArgs()
            {
                RemovedItem = item
            });
        }