aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data/Repositories/PostRepository.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-31 12:58:44 +0200
committertranstrike <transtrike@gmail.com>2021-01-31 12:58:44 +0200
commit979a86a14cd658b5346279901ac8bca667c373d3 (patch)
tree9791cf02c0838a4d6392e3651f93eeed283acb57 /src/DevHive.Data/Repositories/PostRepository.cs
parent9d5f4628a3a75871b47ac6a9f9c0419748d9dfb8 (diff)
parentb8743cfdd0515e4d07ea5c926be1d9ade5340a91 (diff)
downloadDevHive-979a86a14cd658b5346279901ac8bca667c373d3.tar
DevHive-979a86a14cd658b5346279901ac8bca667c373d3.tar.gz
DevHive-979a86a14cd658b5346279901ac8bca667c373d3.zip
Username added to JWT; Promotion to Admin fixed
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)
{