aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-23 22:34:43 +0200
committertranstrike <transtrike@gmail.com>2021-01-23 22:34:43 +0200
commite01a81954e0fba2c4521e03a76f48a970a87994f (patch)
treed2fdacbed68de0f4f32b1d949d75bc1de9f861d3 /src/DevHive.Data/Repositories
parentfac1bf2d1772e60cbecc1cf0381c6063a0e97ffd (diff)
downloadDevHive-e01a81954e0fba2c4521e03a76f48a970a87994f.tar
DevHive-e01a81954e0fba2c4521e03a76f48a970a87994f.tar.gz
DevHive-e01a81954e0fba2c4521e03a76f48a970a87994f.zip
All Post&Comment Implemented; Initializing testing...
Diffstat (limited to 'src/DevHive.Data/Repositories')
-rw-r--r--src/DevHive.Data/Repositories/CommentRepository.cs37
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs54
2 files changed, 39 insertions, 52 deletions
diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs
new file mode 100644
index 0000000..880631a
--- /dev/null
+++ b/src/DevHive.Data/Repositories/CommentRepository.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Threading.Tasks;
+using DevHive.Data.Interfaces.Repositories;
+using DevHive.Data.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace DevHive.Data.Repositories
+{
+ public class CommentRepository : BaseRepository<Comment>, ICommentRepository
+ {
+ private readonly DevHiveContext _context;
+
+ public CommentRepository(DevHiveContext context)
+ : base(context)
+ {
+ this._context = context;
+ }
+
+ #region Read
+ public async Task<Comment> GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
+ {
+ return await this._context.Comments
+ .FirstOrDefaultAsync(p => p.IssuerId == issuerId &&
+ p.TimeCreated == timeCreated);
+ }
+ #endregion
+
+ #region Validations
+ public async Task<bool> DoesCommentExist(Guid id)
+ {
+ return await this._context.Comments
+ .AsNoTracking()
+ .AnyAsync(r => r.Id == id);
+ }
+ #endregion
+ }
+}
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 9230a2e..a79eacf 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -16,56 +16,13 @@ namespace DevHive.Data.Repositories
this._context = context;
}
- #region Create
- public async Task<bool> AddCommentAsync(Comment entity)
- {
- await this._context.Comments
- .AddAsync(entity);
-
- return await this.SaveChangesAsync(this._context);
- }
- #endregion
-
#region Read
- public async Task<Post> GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
+ public async Task<Post> GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated)
{
return await this._context.Posts
- .FirstOrDefaultAsync(p => p.IssuerId == issuerId &&
+ .FirstOrDefaultAsync(p => p.CreatorId == creatorId &&
p.TimeCreated == timeCreated);
}
-
- public async Task<Comment> GetCommentByIdAsync(Guid id)
- {
- return await this._context.Comments
- .FindAsync(id);
- }
-
- public async Task<Comment> GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated)
- {
- return await this._context.Comments
- .FirstOrDefaultAsync(p => p.IssuerId == issuerId &&
- p.TimeCreated == timeCreated);
- }
- #endregion
-
- #region Update
- public async Task<bool> EditCommentAsync(Comment newEntity)
- {
- this._context.Comments
- .Update(newEntity);
-
- return await this.SaveChangesAsync(this._context);
- }
- #endregion
-
- #region Delete
- public async Task<bool> DeleteCommentAsync(Comment entity)
- {
- this._context.Comments
- .Remove(entity);
-
- return await this.SaveChangesAsync(this._context);
- }
#endregion
#region Validations
@@ -75,13 +32,6 @@ namespace DevHive.Data.Repositories
.AsNoTracking()
.AnyAsync(r => r.Id == postId);
}
-
- public async Task<bool> DoesCommentExist(Guid id)
- {
- return await this._context.Comments
- .AsNoTracking()
- .AnyAsync(r => r.Id == id);
- }
#endregion
}
}