From a7bd16b35123c572711104ab8d2de315a4339fca Mon Sep 17 00:00:00 2001 From: Pasindu Prabhashitha Date: Sat, 8 Apr 2023 18:24:16 +0530 Subject: [PATCH] =?UTF-8?q?fix=E2=9C=A8:=20Roll=20back=20to=20object=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Florage.Shared/Contracts/IRepository.cs | 7 +++---- .../Repositories/GenericRepository.cs | 17 ++++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/services/Florage.Shared/Contracts/IRepository.cs b/src/services/Florage.Shared/Contracts/IRepository.cs index 46a8e48..e03f5ac 100644 --- a/src/services/Florage.Shared/Contracts/IRepository.cs +++ b/src/services/Florage.Shared/Contracts/IRepository.cs @@ -5,12 +5,11 @@ namespace Florage.Shared.Contracts public interface IRepository where T : class { Task CreateAsync(T entity); - Task DeleteAsync(string attribute, string value); + Task DeleteAsync(string id); Task> GetAllAsync(); Task> GetAllAsync(Expression> filter); Task FilterAsync(Expression> filter); - Task GetByIdAsync(string id); - Task GetOneAsync(string attribute, string value); - Task UpdateAsync(string attribute, string value, T entity); + Task GetByIdAsync(string id); + Task UpdateAsync(string id, T entity); } } diff --git a/src/services/Florage.Shared/Repositories/GenericRepository.cs b/src/services/Florage.Shared/Repositories/GenericRepository.cs index 4082301..89064e9 100644 --- a/src/services/Florage.Shared/Repositories/GenericRepository.cs +++ b/src/services/Florage.Shared/Repositories/GenericRepository.cs @@ -19,10 +19,10 @@ public async Task CreateAsync(T entity) await dbCollection.InsertOneAsync(entity); } - public async Task DeleteAsync(string attribute, string value) + public async Task DeleteAsync(string id) { - await dbCollection.DeleteOneAsync(filterBuilder.Eq(attribute, value)); - } + await dbCollection.DeleteOneAsync(filterBuilder.Eq("Id", id)); + } public async Task FilterAsync(Expression> filter) { @@ -42,17 +42,12 @@ public async Task> GetAllAsync(Expression> public async Task GetByIdAsync(string id) { return await dbCollection.Find(filterBuilder.Eq("Id", id)).FirstOrDefaultAsync(); - } + } - public async Task GetOneAsync(string attribute, string value) + public async Task UpdateAsync(string id, T entity) { - return await dbCollection.Find(filterBuilder.Eq(attribute, value)).FirstOrDefaultAsync(); + await dbCollection.ReplaceOneAsync(filterBuilder.Eq("Id", id), entity); } - public async Task UpdateAsync(string attribute, string value,T entity) - { - await dbCollection.ReplaceOneAsync(filterBuilder.Eq(attribute, value), entity); - } - } }