diff --git a/IO/IStore.cs b/IO/IStore.cs index a39ca26..a726f53 100644 --- a/IO/IStore.cs +++ b/IO/IStore.cs @@ -6,5 +6,9 @@ public interface IStore : IDisposable public bool Add(T item); + public bool Has(T item); + + public bool Remove(T item); + public IEnumerable GetValues(); } diff --git a/IO/LocalStore.cs b/IO/LocalStore.cs index 1f60230..7395d5b 100644 --- a/IO/LocalStore.cs +++ b/IO/LocalStore.cs @@ -29,6 +29,9 @@ public class LocalStore : IStore using (FileStream fs = new FileStream(this.filePath, FileMode.OpenOrCreate)) using (StreamWriter writer = new StreamWriter(fs, DefaultEncoding)) { + fs.Seek(0, SeekOrigin.Begin); + fs.SetLength(0); + foreach (T item in this.items) { string json = JsonSerializer.Serialize(item); @@ -53,6 +56,16 @@ public class LocalStore : IStore return true; } + public bool Has(T item) + { + return this.items.Contains(item); + } + + public bool Remove(T item) + { + return this.items.Remove(item); + } + public IEnumerable GetValues() { return this.items.ToList(); diff --git a/JsonDB.cs b/JsonDB.cs index b9eb24a..fd2d58c 100644 --- a/JsonDB.cs +++ b/JsonDB.cs @@ -26,6 +26,16 @@ public class JsonDB : IDisposable return this.store.Add(item); } + public bool Has(T item) + { + return this.store.Has(item); + } + + public bool Remove(T item) + { + return this.store.Remove(item); + } + public IEnumerable GetValues() { return this.store.GetValues();