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 { private readonly DbContext _context; public RoleRepository(DbContext context) { this._context = context; } //Create public async Task AddAsync(Role entity) { await this._context .Set() .AddAsync(entity); await this._context.SaveChangesAsync(); } //Read public async Task GetByIdAsync(Guid id) { return await this._context .Set() .FindAsync(id); } //Update public async Task EditAsync(Role newEntity) { this._context .Set() .Update(newEntity); await this._context.SaveChangesAsync(); } //Delete public async Task DeleteAsync(Role entity) { this._context .Set() .Remove(entity); await this._context.SaveChangesAsync(); } public async Task DoesNameExist(string name) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Name == name); } public async Task DoesRoleExist(Guid id) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Id == id); } } }