Improve DeleteCommand
This commit is contained in:
		@@ -10,28 +10,52 @@ namespace TBDel.Commands
 | 
			
		||||
            var dbService = new DbService();
 | 
			
		||||
            if (args.Length > 1 && uint.TryParse(args[1], out uint id))
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine($"Deleting entry with ID: {id}");
 | 
			
		||||
                bool fileDeleted = await dbService.RemoveFileEntryAsync(id);
 | 
			
		||||
                bool folderDeleted = await dbService.RemoveFolderEntryAsync(id);
 | 
			
		||||
 | 
			
		||||
                if (fileDeleted || folderDeleted)
 | 
			
		||||
                {
 | 
			
		||||
                    Console.ForegroundColor = ConsoleColor.Green;
 | 
			
		||||
                    Console.WriteLine("Entry deleted successfully.");
 | 
			
		||||
                    Console.ResetColor();
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                Console.ForegroundColor = ConsoleColor.Yellow;
 | 
			
		||||
                Console.WriteLine($"Are you sure you want to permanently delete entry with ID {id}? (y/N)");
 | 
			
		||||
                Console.ResetColor();
 | 
			
		||||
                var input = Console.ReadLine();
 | 
			
		||||
                if (input != "y")
 | 
			
		||||
                {
 | 
			
		||||
                    Console.ForegroundColor = ConsoleColor.Red;
 | 
			
		||||
                    Console.WriteLine("Something went wrong. Entry not found.");
 | 
			
		||||
                    Console.WriteLine("Operation cancelled.");
 | 
			
		||||
                    Console.ResetColor();
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                Console.ForegroundColor = ConsoleColor.Red;
 | 
			
		||||
                Console.WriteLine("Invalid or missing ID argument.");
 | 
			
		||||
                Console.ResetColor();
 | 
			
		||||
 | 
			
		||||
                if (File.Exists(args[1]))
 | 
			
		||||
                {
 | 
			
		||||
                    File.Delete(args[1]);
 | 
			
		||||
                    if (await dbService.RemoveFileEntryAsync(id))
 | 
			
		||||
                    {
 | 
			
		||||
                        Console.ForegroundColor = ConsoleColor.Green;
 | 
			
		||||
                        Console.WriteLine("File deleted successfully.");
 | 
			
		||||
                        Console.ResetColor();
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        Console.ForegroundColor = ConsoleColor.Red;
 | 
			
		||||
                        Console.WriteLine("Something went wrong while deleting the file.");
 | 
			
		||||
                        Console.ResetColor();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else if (Directory.Exists(args[1]))
 | 
			
		||||
                {
 | 
			
		||||
                    Directory.Delete(args[1]);
 | 
			
		||||
                    if (await dbService.RemoveFolderEntryAsync(id))
 | 
			
		||||
                    {
 | 
			
		||||
                        Console.ForegroundColor = ConsoleColor.Green;
 | 
			
		||||
                        Console.WriteLine("Directory deleted successfully.");
 | 
			
		||||
                        Console.ResetColor();
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        Console.ForegroundColor = ConsoleColor.Red;
 | 
			
		||||
                        Console.WriteLine("Something went wrong while deleting the directory.");
 | 
			
		||||
                        Console.ResetColor();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ public static class HelpCommand
 | 
			
		||||
        Console.WriteLine("Usage: tbdel <command> [arguments]");
 | 
			
		||||
        Console.WriteLine("Available commands:");
 | 
			
		||||
        Console.WriteLine("  add <path to file or folder>       Add a file or folder to the list");
 | 
			
		||||
        Console.WriteLine("  delete <path to file or folder OR file ID>         Deletes a file or folder from the list");
 | 
			
		||||
        Console.WriteLine("  delete <file or folder ID>         Deletes a file or folder");
 | 
			
		||||
        Console.WriteLine("  deleteall        Deletes all items in the list");
 | 
			
		||||
        Console.WriteLine("  list             Lists all items in the list");
 | 
			
		||||
        Console.WriteLine("  help             Shows this help message");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user