diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-15 10:58:05 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-15 10:58:05 +0200 |
| commit | 6bfc34a142279743df82bdb2d3913cafa3051651 (patch) | |
| tree | dfb19c95aade5ce43840661ba3078c60419be2c8 /src | |
| parent | dffe90b75a33076760ebf7e0a006b015cca96767 (diff) | |
| download | DevHive-6bfc34a142279743df82bdb2d3913cafa3051651.tar DevHive-6bfc34a142279743df82bdb2d3913cafa3051651.tar.gz DevHive-6bfc34a142279743df82bdb2d3913cafa3051651.zip | |
UserRepository refactored
Diffstat (limited to 'src')
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 42 |
1 files changed, 21 insertions, 21 deletions
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<User>() .Any(x => x.Id == id); } public bool HasThisUsername(Guid id, string username) { - return this._dbRepository.DbSet + return this._context + .Set<User>() .Any(x => x.Id == id && x.UserName == username); - } */ + } public async Task AddAsync(User entity) { @@ -61,19 +51,29 @@ namespace DevHive.Data.Repositories } - public Task<User> FindByIdAsync(Guid id) + public async Task<User> FindByIdAsync(Guid id) { - throw new System.NotImplementedException(); + return await this._context + .Set<User>() + .FindAsync(id); } - public Task EditAsync(object id, User newEntity) + public async Task EditAsync(User newEntity) { - throw new System.NotImplementedException(); + this._context + .Set<User>() + .Update(newEntity); + + await this._context.SaveChangesAsync(); } - public Task DeleteAsync(object id) + public async Task DeleteAsync(User entity) { - throw new System.NotImplementedException(); + this._context + .Set<User>() + .Remove(entity); + + await this._context.SaveChangesAsync(); } } } |
