From fb56c49681746c8c47c1da43c918b37df5f214a1 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 30 Dec 2020 17:48:30 +0200 Subject: Adding coomment layers --- src/DevHive.Data/Repositories/CommentRepository.cs | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/DevHive.Data/Repositories/CommentRepository.cs (limited to 'src/DevHive.Data/Repositories') diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs new file mode 100644 index 0000000..5a4ef17 --- /dev/null +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -0,0 +1,62 @@ +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); + } + } +} \ No newline at end of file -- cgit v1.2.3