From 58178d5036f65bb4896fea08bbec9388a8ab8c20 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 21 Jan 2021 19:41:28 +0200 Subject: Code cleanup & consistency --- src/DevHive.Data/Repositories/PostRepository.cs | 43 +++++++++++-------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/DevHive.Data/Repositories/PostRepository.cs') diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index db2c4af..71602e7 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -16,11 +16,10 @@ namespace DevHive.Data.Repositories this._context = context; } - //Create + #region Create public async Task AddAsync(Post post) { - await this._context - .Set() + await this._context.Posts .AddAsync(post); return await this.SaveChangesAsync(this._context); @@ -28,18 +27,17 @@ namespace DevHive.Data.Repositories public async Task AddCommentAsync(Comment entity) { - await this._context - .Set() + await this._context.Comments .AddAsync(entity); return await this.SaveChangesAsync(this._context); } + #endregion - //Read + #region Read public async Task GetByIdAsync(Guid id) { - return await this._context - .Set() + return await this._context.Posts .FindAsync(id); } @@ -52,8 +50,7 @@ namespace DevHive.Data.Repositories public async Task GetCommentByIdAsync(Guid id) { - return await this._context - .Set() + return await this._context.Comments .FindAsync(id); } @@ -63,12 +60,12 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(p => p.IssuerId == issuerId && p.TimeCreated == timeCreated); } + #endregion - //Update + #region Update public async Task EditAsync(Post newPost) { - this._context - .Set() + this._context.Posts .Update(newPost); return await this.SaveChangesAsync(this._context); @@ -76,18 +73,17 @@ namespace DevHive.Data.Repositories public async Task EditCommentAsync(Comment newEntity) { - this._context - .Set() + this._context.Comments .Update(newEntity); return await this.SaveChangesAsync(this._context); } + #endregion - //Delete + #region Delete public async Task DeleteAsync(Post post) { - this._context - .Set() + this._context.Posts .Remove(post); return await this.SaveChangesAsync(this._context); @@ -95,27 +91,24 @@ namespace DevHive.Data.Repositories public async Task DeleteCommentAsync(Comment entity) { - this._context - .Set() + this._context.Comments .Remove(entity); return await this.SaveChangesAsync(this._context); } + #endregion #region Validations - public async Task DoesPostExist(Guid postId) { - return await this._context - .Set() + return await this._context.Posts .AsNoTracking() .AnyAsync(r => r.Id == postId); } public async Task DoesCommentExist(Guid id) { - return await this._context - .Set() + return await this._context.Comments .AsNoTracking() .AnyAsync(r => r.Id == id); } -- cgit v1.2.3