public async ValueTask <List <long> > GetMangaIdByFileTreeNodeId(List <long> fileTreeNodeId) { using var context = Context; var mangaService = new MangaService(context); return(await mangaService.GetMangaIds(it => fileTreeNodeId.Contains(it.PathId))); }
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 <List <Manga> > GetMangas(List <long> mangaIds, int offset, int limit, OrderType orderType, bool asc) { using var context = Context; var mangaService = new MangaService(context); return(await mangaService.GetMangas(mangaIds, offset, limit, orderType, asc)); }
public async ValueTask <bool> Update(Manga manga, bool updateChapters) { using var context = Context; var mangaService = new MangaService(context); try { context.BeginTran(); if ((await mangaService.GetSingleAsync(it => it.ObjectId == manga.ObjectId)).Version >= manga.Version) { context.RollbackTran(); return(false); } manga.UpdateTime = DateTime.Now; if (updateChapters && manga.Chapters != null && manga.Chapters.Count != 0) { var chapterService = new ChapterService(context); var imageService = new ImageService(context); var result = await chapterService.Upsert(manga.Chapters); if (result.InsertList.Count != 0) { foreach (var storageableMessage in result.InsertList) { DataFormatter.Format(storageableMessage.Item); await imageService.Upsert(storageableMessage.Item.Images); } } } if (manga.Tags != null) { var mangaTagMappingService = new MangaTagMappingService(context); await mangaTagMappingService.DeleteTagByMangaId(manga.ObjectId); var mangaTagMappings = manga.Tags.Select(tag => new MangaTagMapping() { MangaId = manga.ObjectId, TagId = tag.Key }).ToList(); if (mangaTagMappings.Count > 0) { await mangaTagMappingService.Insert(mangaTagMappings); } } await mangaService.Upsert(manga); FtsIndexService.UpdateFtsIndex(manga); context.CommitTran(); return(true); } catch (Exception e) { context.RollbackTran(); throw; } }
public async ValueTask <Manga> GetManga(long pathId) { using var context = Context; var mangaService = new MangaService(context); var chapterService = new ChapterService(context); var mangaTagMappingService = new MangaTagMappingService(context); var manga = await mangaService.GetSingleAsync(it => it.PathId == pathId); manga.Chapters = await chapterService.GetListAsync(it => it.MangaId == manga.ObjectId); manga.Tags = await mangaTagMappingService.GetTagByMangaId(manga.ObjectId); return(manga); }
public async ValueTask <bool> Insert(Manga manga) { if (!DataFormatter.Format(manga)) { return(false); } using var context = Context; try { context.BeginTran(); var mangaService = new MangaService(context); await mangaService.Upsert(manga); var chapterService = new ChapterService(context); await chapterService.Upsert(manga.Chapters); var imageService = new ImageService(context); var images = manga.Chapters.SelectMany(it => it.Images).ToList(); images.Add(manga.Cover); await imageService.Upsert(images); if (manga.Tags != null && manga.Tags.Count > 0) { var mangaTagMappingService = new MangaTagMappingService(context); var mappings = manga.Tags.Select(it => new MangaTagMapping() { MangaId = manga.ObjectId, TagId = it.Key }).ToList(); await mangaTagMappingService.Insert(mappings); } FtsIndexService.CreateFtsIndex(new List <Manga>() { manga }); 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; } }