public async ValueTask <ReadProgress> GetReadProgress(long userId, long chapterId) { using var context = Context; var readProgressService = new ReadProgressService(context); return(await readProgressService.GetSingleAsync(it => it.UserId == userId && it.ChapterId == chapterId)); }
public async ValueTask <Chapter> GetChapter(long chapterId, long userId) { using var context = Context; var chapterService = new ChapterService(context); var imageService = new ImageService(context); var readProgressService = new ReadProgressService(context); var chapter = await chapterService.GetSingleAsync(it => it.ObjectId == chapterId); chapter.ReadProgress = await readProgressService.GetSingleAsync(it => it.ChapterId == chapterId && it.UserId == userId); chapter.Images = await imageService.GetListAsync(it => it.ChapterId == chapterId); var uncheckedImage = chapter.Images.Where(it => it.Height == 0).ToList(); if (uncheckedImage.Count == 0) { return(chapter); } foreach (var image in uncheckedImage) { await using var file = LibraryManager.GeFileTreeNode(image.PathId).OpenRead(); var(result, width, height) = await ImageUtils.GetMetadata(file); file.Close(); image.Height = height; image.Width = width; } context.BeginTran(); await imageService.Upsert(uncheckedImage); context.CommitTran(); return(chapter); }