using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { public class LanguageRepository : IRepository { private readonly DevHiveContext _context; public LanguageRepository(DevHiveContext context) { this._context = context; } //Create public async Task AddAsync(Language entity) { await this._context .Set() .AddAsync(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } //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 RepositoryMethods.SaveChangesAsync(this._context); } //Delete public async Task DeleteAsync(Language entity) { this._context .Set() .Remove(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } } }