diff options
| author | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-02-13 16:20:18 +0200 |
| commit | 98e17766b203734a1817eed94338e2d25f4395f7 (patch) | |
| tree | 1266385a56cba56fd55c7faf661dd844bbdf5705 /src/Data/DevHive.Data/Repositories/RatingRepository.cs | |
| parent | 1ab34accfda22ee3ce5c7700e3b97ff3e932d649 (diff) | |
| download | DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar.gz DevHive-98e17766b203734a1817eed94338e2d25f4395f7.zip | |
Project Restructure P.1
Diffstat (limited to 'src/Data/DevHive.Data/Repositories/RatingRepository.cs')
| -rw-r--r-- | src/Data/DevHive.Data/Repositories/RatingRepository.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Data/DevHive.Data/Repositories/RatingRepository.cs b/src/Data/DevHive.Data/Repositories/RatingRepository.cs new file mode 100644 index 0000000..1be8fe8 --- /dev/null +++ b/src/Data/DevHive.Data/Repositories/RatingRepository.cs @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class RatingRepository : BaseRepository<Rating>, IRatingRepository + { + private readonly DevHiveContext _context; + private readonly IPostRepository _postRepository; + + public RatingRepository(DevHiveContext context, IPostRepository postRepository) + : base(context) + { + this._context = context; + this._postRepository = postRepository; + } + + public async Task<Rating> GetRatingByPostId(Guid postId) + { + return await this._context.Rating + .FirstOrDefaultAsync(x => x.Post.Id == postId); + } + + public async Task<bool> UserRatedPost(Guid userId, Guid postId) + { + return await this._context.UserRate + .Where(x => x.Post.Id == postId) + .AnyAsync(x => x.User.Id == userId); + } + } +} |
