aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/PostRepository.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-01-30 11:44:56 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-01-30 11:44:56 +0200
commit19ef5e2cdbad996da58787c0fb22a35ab3dd59e8 (patch)
tree74f5f4426b2ec369763f32e06bf63cd18995f8bf /src/DevHive.Data/Repositories/PostRepository.cs
parent8b164bf4ac8c307de933b476e858e489a64c0da5 (diff)
downloadDevHive-19ef5e2cdbad996da58787c0fb22a35ab3dd59e8.tar
DevHive-19ef5e2cdbad996da58787c0fb22a35ab3dd59e8.tar.gz
DevHive-19ef5e2cdbad996da58787c0fb22a35ab3dd59e8.zip
Fixed comment and post getting and updating
Diffstat (limited to 'src/DevHive.Data/Repositories/PostRepository.cs')
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 78b40cd..07b5875 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -23,6 +23,7 @@ namespace DevHive.Data.Repositories
{
return await this._context.Posts
.Include(x => x.Comments)
+ .Include(x => x.Creator)
.FirstOrDefaultAsync(x => x.Id == id);
}
@@ -39,6 +40,30 @@ namespace DevHive.Data.Repositories
}
#endregion
+ #region Update
+ public override async Task<bool> EditAsync(Guid id, Post newEntity)
+ {
+ Post post = await this.GetByIdAsync(id);
+
+ this._context
+ .Entry(post)
+ .CurrentValues
+ .SetValues(newEntity);
+
+ post.FileUrls.Clear();
+ foreach(var fileUrl in newEntity.FileUrls)
+ post.FileUrls.Add(fileUrl);
+
+ post.Comments.Clear();
+ foreach(var comment in newEntity.Comments)
+ post.Comments.Add(comment);
+
+ this._context.Entry(post).State = EntityState.Modified;
+
+ return await this.SaveChangesAsync(this._context);
+ }
+ #endregion
+
#region Validations
public async Task<bool> DoesPostExist(Guid postId)
{