diff options
Diffstat (limited to 'src/DevHive.Data/Repositories')
| -rw-r--r-- | src/DevHive.Data/Repositories/CommentRepository.cs | 37 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/PostRepository.cs | 54 |
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 } } |
