diff options
Diffstat (limited to 'src/DevHive.Data/Repositories/RoleRepository.cs')
| -rw-r--r-- | src/DevHive.Data/Repositories/RoleRepository.cs | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 1c40b04..9b6cf14 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -2,32 +2,72 @@ using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { public class RoleRepository : IRepository<Role> { + private readonly DbContext _context; + + public RoleRepository(DbContext context) + { + this._context = context; + } + + //Create public async Task AddAsync(Role entity) { - throw new NotImplementedException(); + await this._context + .Set<Role>() + .AddAsync(entity); + + await this._context.SaveChangesAsync(); } - //Find entity by id + //Read public async Task<Role> GetByIdAsync(Guid id) { - throw new NotImplementedException(); + return await this._context + .Set<Role>() + .FindAsync(id); + } - //Modify Entity from database + //Update public async Task EditAsync(Role newEntity) { - throw new NotImplementedException(); - } + this._context + .Set<Role>() + .Update(newEntity); - //Delete Entity from database + await this._context.SaveChangesAsync(); + } + + //Delete public async Task DeleteAsync(Role entity) { - throw new NotImplementedException(); + this._context + .Set<Role>() + .Remove(entity); + + await this._context.SaveChangesAsync(); + } + + public async Task<bool> DoesNameExist(string name) + { + return await this._context + .Set<Role>() + .AsNoTracking() + .AnyAsync(r => r.Name == name); + } + + public async Task<bool> DoesRoleExist(Guid id) + { + return await this._context + .Set<Role>() + .AsNoTracking() + .AnyAsync(r => r.Id == id); } } } |
