using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; using DevHive.Common.Models.Data; namespace DevHive.Data.Repositories { public class TechnologyRepository : IRepository { private readonly DevHiveContext _context; public TechnologyRepository(DevHiveContext context) { this._context = context; } //Create public async Task AddAsync(Technology 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 DoesTechnologyNameExist(string technologyName) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Name == technologyName); } public async Task DoesTechnologyExist(Guid id) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Id == id); } //Edit public async Task EditAsync(Technology newEntity) { this._context .Set() .Update(newEntity); return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete public async Task DeleteAsync(Technology entity) { this._context .Set() .Remove(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } } }