Add duplicate path check
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics.Contracts;
|
||||||
using TBDel.Models;
|
using TBDel.Models;
|
||||||
using TBDel.Services;
|
using TBDel.Services;
|
||||||
|
|
||||||
@@ -7,9 +8,6 @@ namespace TBDel.Commands
|
|||||||
{
|
{
|
||||||
public static async Task AddEntry(string[] args)
|
public static async Task AddEntry(string[] args)
|
||||||
{
|
{
|
||||||
// TODO: Add duplicate path check
|
|
||||||
// TODO: Add support for multiple paths
|
|
||||||
|
|
||||||
if (args.Length > 1)
|
if (args.Length > 1)
|
||||||
{
|
{
|
||||||
string workingDirectory = Directory.GetCurrentDirectory();
|
string workingDirectory = Directory.GetCurrentDirectory();
|
||||||
@@ -19,6 +17,12 @@ namespace TBDel.Commands
|
|||||||
if (File.Exists(absolutePath))
|
if (File.Exists(absolutePath))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Adding: {absolutePath}");
|
Console.WriteLine($"Adding: {absolutePath}");
|
||||||
|
if (await dbService.EtryExists(absolutePath))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("File already exists in the list - No actions performed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
var entry = new FileEntry { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
var entry = new FileEntry { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
||||||
if (await dbService.AddFileEntryAsync(entry))
|
if (await dbService.AddFileEntryAsync(entry))
|
||||||
{
|
{
|
||||||
@@ -38,6 +42,12 @@ namespace TBDel.Commands
|
|||||||
else if (Directory.Exists(absolutePath))
|
else if (Directory.Exists(absolutePath))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Adding: {absolutePath}");
|
Console.WriteLine($"Adding: {absolutePath}");
|
||||||
|
if (await dbService.EtryExists(absolutePath))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("Folder already exists in the list - No actions performed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
var entry = new FolderEntry() { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
var entry = new FolderEntry() { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
||||||
if (await dbService.AddFolderEntryAsync(entry))
|
if (await dbService.AddFolderEntryAsync(entry))
|
||||||
{
|
{
|
||||||
|
@@ -4,7 +4,6 @@ namespace TBDel
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
// TODO: Add a command to show the Db path
|
|
||||||
// TODO: Add a command to remove a file or folder only from the list
|
// TODO: Add a command to remove a file or folder only from the list
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
@@ -106,6 +106,16 @@ namespace TBDel.Services
|
|||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> EtryExists(String path)
|
||||||
|
{
|
||||||
|
if (_fileCollection.Find(f => f.Path == path) is not null || _folderCollection.Find(f => f.Path == path) is not null)
|
||||||
|
{
|
||||||
|
return await Task.FromResult(true);
|
||||||
|
}
|
||||||
|
return await Task.FromResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DatabaseContent
|
public class DatabaseContent
|
||||||
|
Reference in New Issue
Block a user