aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2020-12-30 17:48:30 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2020-12-30 17:48:30 +0200
commitfb56c49681746c8c47c1da43c918b37df5f214a1 (patch)
tree780a7ae16198a0649988cd4a677e984477ffb150 /src/DevHive.Data/Repositories
parente2958817c79f29722fedc1ea8ddcedea894a0f20 (diff)
downloadDevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.tar
DevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.tar.gz
DevHive-fb56c49681746c8c47c1da43c918b37df5f214a1.zip
Adding coomment layers
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/CommentRepository.cs62
1 files changed, 62 insertions, 0 deletions
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<Comment>
+ {
+ private readonly DevHiveContext _context;
+
+ public CommentRepository(DevHiveContext context)
+ {
+ this._context = context;
+ }
+
+ public async Task<bool> AddAsync(Comment entity)
+ {
+ await this._context
+ .Set<Comment>()
+ .AddAsync(entity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<Comment> GetByIdAsync(Guid id)
+ {
+ return await this._context
+ .Set<Comment>()
+ .FindAsync(id);
+ }
+
+
+ public async Task<bool> EditAsync(Comment newEntity)
+ {
+ this._context
+ .Set<Comment>()
+ .Update(newEntity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> DoesCommentExist(Guid id)
+ {
+ return await this._context
+ .Set<Comment>()
+ .AsNoTracking()
+ .AnyAsync(r => r.Id == id);
+ }
+
+ public async Task<bool> DeleteAsync(Comment entity)
+ {
+ this._context
+ .Set<Comment>()
+ .Remove(entity);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+ }
+} \ No newline at end of file