profileShare

rasmusjy / splitapp-backend-clean-onion

Read-only snapshot

No repository description.

main default branch 429 files Expires Sep 13, 2026, 9:06 AM
TripPollRepository.cs 1,590 bytes
1 using App.Domain;
2 using App.Domain.Contracts;
3 using Microsoft.EntityFrameworkCore;
4
5 namespace App.DAL.EF.Repositories;
6
7 public class TripPollRepository : BaseRepository<TripPoll>, ITripPollRepository
8 {
9 public TripPollRepository(AppDbContext dbContext) : base(dbContext)
10 {
11 }
12
13 public override async Task<IEnumerable<TripPoll>> GetAllAsync()
14 {
15 return await DbContext.TripPolls
16 .Include(p => p.Trip)
17 .Include(p => p.CreatedByUser)
18 .Include(p => p.Options!)
19 .ThenInclude(o => o.Votes)
20 .ToListAsync();
21 }
22
23 public override async Task<TripPoll?> GetByIdAsync(Guid id)
24 {
25 return await DbContext.TripPolls
26 .Include(p => p.Trip)
27 .Include(p => p.CreatedByUser)
28 .Include(p => p.Options!)
29 .ThenInclude(o => o.Votes)
30 .FirstOrDefaultAsync(p => p.Id == id);
31 }
32
33 public async Task<IEnumerable<TripPoll>> GetByTripIdAsync(Guid tripId)
34 {
35 return await DbContext.TripPolls
36 .Where(p => p.TripId == tripId)
37 .Include(p => p.CreatedByUser)
38 .Include(p => p.Options!)
39 .ThenInclude(o => o.Votes)
40 .ToListAsync();
41 }
42
43 public async Task<TripPoll?> GetByIdWithDetailsAsync(Guid id)
44 {
45 return await DbContext.TripPolls
46 .Include(p => p.CreatedByUser)
47 .Include(p => p.Options!)
48 .ThenInclude(o => o.Votes!)
49 .ThenInclude(v => v.User)
50 .FirstOrDefaultAsync(p => p.Id == id);
51 }
52 }
53