using System; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { public class RoleRepository : BaseRepository, IRoleRepository { private readonly DevHiveContext _context; public RoleRepository(DevHiveContext context) :base(context) { this._context = context; } #region Read public async Task GetByNameAsync(string name) { return await this._context.Roles .FirstOrDefaultAsync(x => x.Name == name); } #endregion #region Validations public async Task DoesNameExist(string name) { return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Name == name); } public async Task DoesRoleExist(Guid id) { return await this._context.Roles .AsNoTracking() .AnyAsync(r => r.Id == id); } #endregion } }