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 CommentRepository : IRepository { private readonly DevHiveContext _context; public CommentRepository(DevHiveContext context) { this._context = context; } public async Task AddAsync(Comment entity) { await this._context .Set() .AddAsync(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } public async Task GetByIdAsync(Guid id) { return await this._context .Set() .FindAsync(id); } public async Task EditAsync(Comment newEntity) { this._context .Set() .Update(newEntity); return await RepositoryMethods.SaveChangesAsync(this._context); } public async Task DoesCommentExist(Guid id) { return await this._context .Set() .AsNoTracking() .AnyAsync(r => r.Id == id); } public async Task DeleteAsync(Comment entity) { this._context .Set() .Remove(entity); return await RepositoryMethods.SaveChangesAsync(this._context); } } }