diff options
Diffstat (limited to 'src/DevHive.Data')
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 73 |
1 files changed, 53 insertions, 20 deletions
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); + } } } |
