using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { public class LanguageRepository : IRepository { private readonly DbContext _context; public LanguageRepository(DbContext context) { this._context = context; } //Create public async Task AddAsync(Language entity) { await this._context .Set() .AddAsync(entity); return await this.SaveChangesAsync(); } //Read public async Task GetByIdAsync(Guid id) { return await this._context .Set() .FindAsync(id); } public async Task DoesLanguageNameExist(string languageName) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Name == languageName); } public async Task DoesLanguageExist(Guid id) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Id == id); } //Update public async Task EditAsync(Language newEntity) { this._context .Set() .Update(newEntity); return await this.SaveChangesAsync(); } //Delete public async Task DeleteAsync(Language entity) { this._context .Set() .Remove(entity); return await this.SaveChangesAsync(); } private async Task SaveChangesAsync() { int result = await this._context.SaveChangesAsync(); return result >= 0; } } }