aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/PostRepository.cs
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 20:53:13 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-01-21 20:53:13 +0200
commitbd67366f41a25e868053bf3c71ed2917f25a8a6f (patch)
treea5754fcf564b09a42f884a58d2fd707e44ab8044 /src/DevHive.Data/Repositories/PostRepository.cs
parent5e5e2eb2edef88840edbb072597f81f8da3ae929 (diff)
parent78884a445ec3f21d06e5859d03009b7d71bbb784 (diff)
downloadDevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.tar
DevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.tar.gz
DevHive-bd67366f41a25e868053bf3c71ed2917f25a8a6f.zip
fixing edit methods in repos
Diffstat (limited to 'src/DevHive.Data/Repositories/PostRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs43
1 files changed, 18 insertions, 25 deletions
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<bool> AddAsync(Post post)
{
- await this._context
- .Set<Post>()
+ await this._context.Posts
.AddAsync(post);
return await this.SaveChangesAsync(this._context);
@@ -28,18 +27,17 @@ namespace DevHive.Data.Repositories
public async Task<bool> AddCommentAsync(Comment entity)
{
- await this._context
- .Set<Comment>()
+ await this._context.Comments
.AddAsync(entity);
return await this.SaveChangesAsync(this._context);
}
+ #endregion
- //Read
+ #region Read
public async Task<Post> GetByIdAsync(Guid id)
{
- return await this._context
- .Set<Post>()
+ return await this._context.Posts
.FindAsync(id);
}
@@ -52,8 +50,7 @@ namespace DevHive.Data.Repositories
public async Task<Comment> GetCommentByIdAsync(Guid id)
{
- return await this._context
- .Set<Comment>()
+ 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<bool> EditAsync(Post newPost)
{
- this._context
- .Set<Post>()
+ this._context.Posts
.Update(newPost);
return await this.SaveChangesAsync(this._context);
@@ -76,18 +73,17 @@ namespace DevHive.Data.Repositories
public async Task<bool> EditCommentAsync(Comment newEntity)
{
- this._context
- .Set<Comment>()
+ this._context.Comments
.Update(newEntity);
return await this.SaveChangesAsync(this._context);
}
+ #endregion
- //Delete
+ #region Delete
public async Task<bool> DeleteAsync(Post post)
{
- this._context
- .Set<Post>()
+ this._context.Posts
.Remove(post);
return await this.SaveChangesAsync(this._context);
@@ -95,27 +91,24 @@ namespace DevHive.Data.Repositories
public async Task<bool> DeleteCommentAsync(Comment entity)
{
- this._context
- .Set<Comment>()
+ this._context.Comments
.Remove(entity);
return await this.SaveChangesAsync(this._context);
}
+ #endregion
#region Validations
-
public async Task<bool> DoesPostExist(Guid postId)
{
- return await this._context
- .Set<Post>()
+ return await this._context.Posts
.AsNoTracking()
.AnyAsync(r => r.Id == postId);
}
public async Task<bool> DoesCommentExist(Guid id)
{
- return await this._context
- .Set<Comment>()
+ return await this._context.Comments
.AsNoTracking()
.AnyAsync(r => r.Id == id);
}