SplitPresetRepository.cs
1,319 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 SplitPresetRepository : BaseRepository<SplitPreset>, ISplitPresetRepository |
| 8 | { |
| 9 | public SplitPresetRepository(AppDbContext dbContext) : base(dbContext) |
| 10 | { |
| 11 | } |
| 12 | |
| 13 | public override async Task<IEnumerable<SplitPreset>> GetAllAsync() |
| 14 | { |
| 15 | return await DbContext.SplitPresets |
| 16 | .Include(sp => sp.Trip) |
| 17 | .Include(sp => sp.CreatedBy) |
| 18 | .Include(sp => sp.Members!) |
| 19 | .ThenInclude(m => m.User) |
| 20 | .ToListAsync(); |
| 21 | } |
| 22 | |
| 23 | public override async Task<SplitPreset?> GetByIdAsync(Guid id) |
| 24 | { |
| 25 | return await DbContext.SplitPresets |
| 26 | .Include(sp => sp.Trip) |
| 27 | .Include(sp => sp.CreatedBy) |
| 28 | .Include(sp => sp.Members!) |
| 29 | .ThenInclude(m => m.User) |
| 30 | .FirstOrDefaultAsync(sp => sp.Id == id); |
| 31 | } |
| 32 | |
| 33 | public async Task<IEnumerable<SplitPreset>> GetByTripIdAsync(Guid tripId) |
| 34 | { |
| 35 | return await DbContext.SplitPresets |
| 36 | .Where(sp => sp.TripId == tripId) |
| 37 | .Include(sp => sp.CreatedBy) |
| 38 | .Include(sp => sp.Members!) |
| 39 | .ThenInclude(m => m.User) |
| 40 | .OrderBy(sp => sp.Name) |
| 41 | .ToListAsync(); |
| 42 | } |
| 43 | } |
| 44 | |