Website Summary Files Commits Branches @commit @diff @stats
path: root / src / DevHive.Data / Repositories / UserRepository.cs
diff options
context:
space:
mode:
Commit54d081a513117c732ab4d62312b440d37dfe0d67 (patch)
Author
 transtrike <transtrike@gmail.com>
2020-12-15 19:38:50 +0200
Committer
 transtrike <transtrike@gmail.com>
2020-12-15 19:38:50 +0200
Filesef90a2aefca9da180d71d92256a2b51b91ad65ff /src/DevHive.Data/Repositories/UserRepository.cs
DevHive-54d081a513117c732ab4d62312b440d37dfe0d67.tar
DevHive-54d081a513117c732ab4d62312b440d37dfe0d67.tar.gz
DevHive-54d081a513117c732ab4d62312b440d37dfe0d67.zip
Parent15b69b3036ba6a36ed0de8a64f466c9f46d7f0e9 (diff)
User Controller, Service & Data implemented
1 files changed, 53 insertions, 20 deletions
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs73
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
index 5b30c30..13ee2bc 100644
--- a/src/DevHive.Data/Repositories/UserRepository.cs
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -17,21 +17,7 @@ namespace DevHive.Data.Repositories
this._context = context;
}
- public bool DoesUserExist(Guid id)
- {
- return this._context
- .Set<User>()
- .Any(x => x.Id == id);
- }
-
- public bool HasThisUsername(Guid id, string username)
- {
- return this._context
- .Set<User>()
- .Any(x => x.Id == id &&
- x.UserName == username);
- }
-
+ //Create
public async Task AddAsync(User entity)
{
await this._context
@@ -40,24 +26,31 @@ namespace DevHive.Data.Repositories
await this._context.SaveChangesAsync();
}
-
- public IEnumerable<User> Query(int count)
+
+ //Read
+ public IEnumerable<User> QueryAll()
{
return this._context
.Set<User>()
.AsNoTracking()
- .Take(count)
.AsEnumerable();
-
}
- public async Task<User> FindByIdAsync(Guid id)
+ public async Task<User> GetByIdAsync(Guid id)
{
return await this._context
.Set<User>()
.FindAsync(id);
}
+ public async Task<User> GetByUsername(string username)
+ {
+ return await this._context
+ .Set<User>()
+ .FirstOrDefaultAsync(x => x.UserName == username);
+ }
+
+ //Update
public async Task EditAsync(User newEntity)
{
this._context
@@ -67,6 +60,7 @@ namespace DevHive.Data.Repositories
await this._context.SaveChangesAsync();
}
+ //Delete
public async Task DeleteAsync(User entity)
{
this._context
@@ -75,5 +69,44 @@ namespace DevHive.Data.Repositories
await this._context.SaveChangesAsync();
}
+
+ //Validations
+ public bool DoesUserExist(Guid id)
+ {
+ return this._context
+ .Set<User>()
+ .Any(x => x.Id == id);
+ }
+
+ public Task<bool> IsUsernameValid(string username)
+ {
+ return this._context
+ .Set<User>()
+ .AnyAsync(u => u.UserName == username);
+ }
+
+ public bool DoesUserHaveThisUsername(Guid id, string username)
+ {
+ return this._context
+ .Set<User>()
+ .Any(x => x.Id == id &&
+ x.UserName == username);
+ }
+
+ public async Task<bool> DoesUsernameExist(string username)
+ {
+ return await this._context
+ .Set<User>()
+ .AsNoTracking()
+ .AnyAsync(u => u.UserName == username);
+ }
+
+ public async Task<bool> DoesEmailExist(string email)
+ {
+ return await this._context
+ .Set<User>()
+ .AsNoTracking()
+ .AnyAsync(u => u.Email == email);
+ }
}
}