From 6bfc34a142279743df82bdb2d3913cafa3051651 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 15 Dec 2020 10:58:05 +0200 Subject: UserRepository refactored --- src/DevHive.Data/Repositories/UserRepository.cs | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/DevHive.Data/Repositories/UserRepository.cs') diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 2363200..5b30c30 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -16,31 +16,21 @@ namespace DevHive.Data.Repositories { this._context = context; } - /* - public User FindByUsername(string username) - { - return this._dbRepository.DbSet - .FirstOrDefault(usr => usr.UserName == username); - } - - public bool DoesUsernameExist(string username) - { - return this._dbRepository.DbSet - .Any(x => x.UserName == username); - } public bool DoesUserExist(Guid id) { - return this._dbRepository.DbSet + return this._context + .Set() .Any(x => x.Id == id); } public bool HasThisUsername(Guid id, string username) { - return this._dbRepository.DbSet + return this._context + .Set() .Any(x => x.Id == id && x.UserName == username); - } */ + } public async Task AddAsync(User entity) { @@ -61,19 +51,29 @@ namespace DevHive.Data.Repositories } - public Task FindByIdAsync(Guid id) + public async Task FindByIdAsync(Guid id) { - throw new System.NotImplementedException(); + return await this._context + .Set() + .FindAsync(id); } - public Task EditAsync(object id, User newEntity) + public async Task EditAsync(User newEntity) { - throw new System.NotImplementedException(); + this._context + .Set() + .Update(newEntity); + + await this._context.SaveChangesAsync(); } - public Task DeleteAsync(object id) + public async Task DeleteAsync(User entity) { - throw new System.NotImplementedException(); + this._context + .Set() + .Remove(entity); + + await this._context.SaveChangesAsync(); } } } -- cgit v1.2.3