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> 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); }