using System; using System.Threading.Tasks; using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { public class TechnologyRepository : ITechnologyRepository { private readonly DevHiveContext _context; public TechnologyRepository(DevHiveContext context) { this._context = context; } #region Create public async Task AddAsync(Technology entity) { await this._context .Set() .AddAsync(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } #endregion #region Read public async Task GetByIdAsync(Guid id) { return await this._context .Set() .FindAsync(id); } #endregion #region Edit public async Task EditAsync(Technology newEntity) { this._context .Set() .Update(newEntity); return await RepositoryMethods.SaveChangesAsync(this._context); } #endregion #region Delete public async Task DeleteAsync(Technology entity) { this._context .Set() .Remove(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } #endregion #region Validations public async Task DoesTechnologyNameExist(string technologyName) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Name == technologyName); } public async Task DoesTechnologyExistAsync(Guid id) { return await this._context.Technologies .AnyAsync(x => x.Id == id); } #endregion } }