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 <Manga> GetManga(long mangaId, long userId) { using var context = Context; var mangaService = new MangaService(context); var chapterService = new ChapterService(context); var mangaTagMappingService = new MangaTagMappingService(context); var favoriteService = new FavoriteService(context); var readProgressService = new ReadProgressService(context); var commentProgressService = new CommentService(context); var manga = await mangaService.GetSingleAsync(it => it.ObjectId == mangaId); manga.Chapters = (await chapterService .GetListAsync(it => it.MangaId == mangaId)) .OrderBy(it => it.Order) .ToList(); manga.Tags = await mangaTagMappingService.GetTagByMangaId(mangaId); if (userId <= 0) { return(manga); } manga.IsFavorite = await favoriteService.IsAnyAsync(it => it.EntityId == mangaId && it.UserId == userId); manga.ReadProgresses = await readProgressService.GetListAsync(it => it.MangaId == mangaId && it.UserId == userId); manga.Comment = await commentProgressService.GetSingleAsync(it => it.EntityId == mangaId && it.UserId == userId); return(manga); }
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 <bool> DeleteManga(long mangaId) { using var context = Context; var mangaService = new MangaService(context); var chapterService = new ChapterService(context); var imageService = new ImageService(context); var mangaTagMappingService = new MangaTagMappingService(context); var favoriteService = new FavoriteService(context); var readProgressService = new ReadProgressService(context); context.BeginTran(); try { var chapters = await chapterService.GetListAsync(it => it.MangaId == mangaId); var chapterIds = chapters.Select(it => it.ObjectId).ToList(); await mangaService.DeleteAsync(it => it.ObjectId == mangaId); await mangaTagMappingService.DeleteAsync(it => it.MangaId == mangaId); await chapterService.DeleteAsync(it => it.MangaId == mangaId); await imageService.DeleteAsync(it => chapterIds.Contains(it.ChapterId)); await favoriteService.DeleteAsync(it => it.EntityId == mangaId); await readProgressService.DeleteAsync(it => it.MangaId == mangaId); context.CommitTran(); FtsIndexService.DeleteMangaFtxIndex(mangaId); 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); }