public async Task <IEnumerable <Song> > GetSongsAsync( Course course, [ScopedService] DatabaseContext dbContext, SongByIdDataLoader songById, CancellationToken cancellationToken) { var songIds = await dbContext.Courses .Where(c => c.Id == course.Id) .Include(c => c.SongDifficulties) .SelectMany(c => c.SongDifficulties.Select(s => s.Id)) .ToArrayAsync(cancellationToken); return(await songById.LoadAsync(songIds, cancellationToken)); }
public async Task <AddCoursePayload> AddCourseAsync( AddCourseInput input, [ScopedService] DatabaseContext context, [ScopedService] SongByIdDataLoader songByIdDataLoader, CancellationToken cancellationToken) { var songDifficulties = context .SongDifficulties .Where(s => input.SongDifficulties.Contains(s.Id)) .ToImmutableList(); var course = new Course { Name = input.Name, Description = input.Description, SongDifficulties = songDifficulties }; var courseEntity = await context.Courses.AddAsync(course, cancellationToken); await context.SaveChangesAsync(cancellationToken); return(new AddCoursePayload(courseEntity.Entity)); }
public async Task <IEnumerable <Song> > GetSongsByIdAsync( [ID(nameof(Song))] Guid[] ids, SongByIdDataLoader songByIdDataLoader, CancellationToken cancellationToken) => await songByIdDataLoader.LoadAsync(ids, cancellationToken) ?? Array.Empty <Song>();
public Task <Song?> GetSongByIdAsync( [ID(nameof(Song))] Guid id, SongByIdDataLoader songByIdDataLoader, CancellationToken cancellationToken) => songByIdDataLoader.LoadAsync(id, cancellationToken) !;