Implemented unique Id for each entry - Implemented delete single entry command

This commit is contained in:
2025-02-04 13:56:40 +03:30
parent 83347587e4
commit 9b1d6aebe7
6 changed files with 194 additions and 175 deletions
+18 -15
View File
@@ -1,35 +1,38 @@
using TBDel.Models;
using TBDel.Services;
namespace TBDel.Commands;
public class DeleteCommand
namespace TBDel.Commands
{
// Will be done by unique file Id
public static async Task DeleteEntry(string[] args)
public class DeleteCommand
{
var dbService = new DbService();
if (args.Length > 1)
public static async Task DeleteEntry(string[] args)
{
if (File.Exists(args[1]))
var dbService = new DbService();
if (args.Length > 1 && uint.TryParse(args[1], out uint id))
{
Console.WriteLine($"Deleteing file: {args[1]}");
if (await dbService.RemoveFileEntryAsync(args[1]))
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("File deleted successfully");
Console.WriteLine("Entry deleted successfully.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("something went wrong");
Console.WriteLine("Something went wrong. Entry not found.");
Console.ResetColor();
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid or missing ID argument.");
Console.ResetColor();
}
}
}
}