public async ValueTask <bool> Upsert(ReadProgress readProgress) { using var context = Context; try { context.BeginTran(); readProgress.ReadTime = DateTime.Now; var chapterService = new ChapterService(context); readProgress.MangaId = (await chapterService.GetSingleAsync(it => it.ObjectId == readProgress.ChapterId)).MangaId; var readProgressService = new ReadProgressService(context); var result = readProgressService.Upsert(readProgress); context.CommitTran(); return(true); } catch (Exception e) { context.RollbackTran(); throw; } }
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); }