Esempio n. 1
0
        public async Task <ActionResult> Delete(int id)
        {
            var result = await itemsService.DeleteItems(id);

            return(Ok(result));
        }
Esempio n. 2
0
        public static void DeleteMultipleItems(IItemsService svc)
        {
            Console.WriteLine("Would you like to delete items as a batch?");
            bool batchDelete = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase);
            var  allItems    = new List <int>();

            bool deleteAnother = true;

            while (deleteAnother == true)
            {
                Console.WriteLine("Items");
                Console.WriteLine("Enter the ID number to delete");
                Console.WriteLine("*******************************");
                var items = svc.ListInventory();
                items.ForEach(x => Console.WriteLine($"ID: {x.Id} | {x.Name}"));
                Console.WriteLine("*******************************");
                if (batchDelete && allItems.Any())
                {
                    Console.WriteLine("Items scheduled for delete");
                    allItems.ForEach(x => Console.Write($"{x},"));
                    Console.WriteLine();
                    Console.WriteLine("*******************************");
                }
                int id = 0;

                if (int.TryParse(Console.ReadLine(), out id))
                {
                    var itemMatch = items.FirstOrDefault(x => x.Id == id);
                    if (itemMatch != null)
                    {
                        if (batchDelete)
                        {
                            if (!allItems.Contains(itemMatch.Id))
                            {
                                allItems.Add(itemMatch.Id);
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Are you sure you want to delete the item {itemMatch.Id}-{itemMatch.Name}");
                            if (Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase))
                            {
                                svc.DeleteItem(itemMatch.Id);
                                Console.WriteLine("Item Deleted");
                            }
                        }
                    }
                }

                Console.WriteLine("Would you like to delete another item?");
                deleteAnother = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase);

                if (batchDelete && !deleteAnother)
                {
                    Console.WriteLine("Are you sure you want to delete the following items: ");
                    allItems.ForEach(x => Console.Write($"{x},"));
                    Console.WriteLine();
                    if (Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase))
                    {
                        svc.DeleteItems(allItems);
                        Console.WriteLine("Items Deleted");
                    }
                }
            }
        }