diff options
| author | transtrike <transtrike@gmail.com> | 2021-02-01 18:28:55 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-02-01 18:28:55 +0200 |
| commit | 6f7c7adced972944f5648b3714baa053037a4160 (patch) | |
| tree | cac3ca1c9b9cc98c1af84c2b46236075a1f1a2f3 /src/DevHive.Data/Repositories | |
| parent | 84f9eebd0895e2c23b5718ee408f056e3cf3ebb2 (diff) | |
| download | DevHive-6f7c7adced972944f5648b3714baa053037a4160.tar DevHive-6f7c7adced972944f5648b3714baa053037a4160.tar.gz DevHive-6f7c7adced972944f5648b3714baa053037a4160.zip | |
GetByUsername & GetById return post Ids; Read POst returns URLs
Diffstat (limited to 'src/DevHive.Data/Repositories')
| -rw-r--r-- | src/DevHive.Data/Repositories/PostRepository.cs | 13 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 31eb7d0..623a8f8 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DevHive.Data.Interfaces.Models; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -11,11 +12,21 @@ namespace DevHive.Data.Repositories public class PostRepository : BaseRepository<Post>, IPostRepository { private readonly DevHiveContext _context; + private readonly IUserRepository _userRepository; - public PostRepository(DevHiveContext context) + public PostRepository(DevHiveContext context, IUserRepository userRepository) : base(context) { this._context = context; + this._userRepository = userRepository; + } + + public async Task<bool> AddNewPostToCreator(Guid userId, Post post) + { + User user = await this._userRepository.GetByIdAsync(userId); + user.Posts.Add(post); + + return await this.SaveChangesAsync(); } #region Read diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 4bf919e..6f33570 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -38,6 +38,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Roles) .Include(x => x.Languages) .Include(x => x.Technologies) + .Include(x => x.Posts) .FirstOrDefaultAsync(x => x.Id == id); } @@ -48,6 +49,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Roles) .Include(x => x.Languages) .Include(x => x.Technologies) + .Include(x => x.Posts) .FirstOrDefaultAsync(x => x.UserName == username); } #endregion |
