diff options
| author | transtrike <transtrike@gmail.com> | 2021-01-21 22:13:16 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-01-21 22:13:16 +0200 |
| commit | 13a2ceda912f961a232c87236f1b29aa29bb6160 (patch) | |
| tree | 59f8d2bf63b03bacc76f98114d2aed78e420ddcd /src/DevHive.Data/Repositories/RoleRepository.cs | |
| parent | a47ea20ab91017da53437f750ed8e0f939f5cdba (diff) | |
| parent | bda98b96433d7a9952524fab4ec65f96998b55de (diff) | |
| download | DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar.gz DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.zip | |
Merge branch 'refactor_user_updating' into dev
Diffstat (limited to 'src/DevHive.Data/Repositories/RoleRepository.cs')
| -rw-r--r-- | src/DevHive.Data/Repositories/RoleRepository.cs | 58 |
1 files changed, 9 insertions, 49 deletions
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index ca3fb8b..156792d 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -1,83 +1,43 @@ using System; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class RoleRepository : IRoleRepository + public class RoleRepository : BaseRepository<Role>, IRoleRepository { private readonly DevHiveContext _context; public RoleRepository(DevHiveContext context) + :base(context) { this._context = context; } - //Create - public async Task<bool> AddAsync(Role entity) - { - await this._context - .Set<Role>() - .AddAsync(entity); - - return await RepositoryMethods.SaveChangesAsync(this._context); - } - - //Read - public async Task<Role> GetByIdAsync(Guid id) - { - return await this._context - .Set<Role>() - .FindAsync(id); - } - + #region Read public async Task<Role> GetByNameAsync(string name) { - return await this._context - .Set<Role>() + return await this._context.Roles .FirstOrDefaultAsync(x => x.Name == name); } + #endregion - //Update - public async Task<bool> EditAsync(Role newEntity) - { - Role role = await this.GetByIdAsync(newEntity.Id); - - this._context - .Entry(role) - .CurrentValues - .SetValues(newEntity); - - return await RepositoryMethods.SaveChangesAsync(this._context); - } - - //Delete - public async Task<bool> DeleteAsync(Role entity) - { - this._context - .Set<Role>() - .Remove(entity); - - return await RepositoryMethods.SaveChangesAsync(this._context); - } - + #region Validations public async Task<bool> DoesNameExist(string name) { - return await this._context - .Set<Role>() + return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Name == name); } public async Task<bool> DoesRoleExist(Guid id) { - return await this._context - .Set<Role>() + return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Id == id); } + #endregion } } |
