aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-15 10:58:05 +0200
committertranstrike <transtrike@gmail.com>2020-12-15 10:58:05 +0200
commit6bfc34a142279743df82bdb2d3913cafa3051651 (patch)
treedfb19c95aade5ce43840661ba3078c60419be2c8 /src/DevHive.Data
parentdffe90b75a33076760ebf7e0a006b015cca96767 (diff)
downloadDevHive-6bfc34a142279743df82bdb2d3913cafa3051651.tar
DevHive-6bfc34a142279743df82bdb2d3913cafa3051651.tar.gz
DevHive-6bfc34a142279743df82bdb2d3913cafa3051651.zip
UserRepository refactored
Diffstat (limited to 'src/DevHive.Data')
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs42
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();
}
}
}