Ejemplo n.º 1
0
        public async ValueTask <bool> AddMangaFavorite(long userId, long mangaId)
        {
            using var context = Context;
            try
            {
                context.BeginTran();
                var favoriteService = new FavoriteService(context);
                var favorite        = new Favorite
                {
                    EntityId   = mangaId,
                    EntityType = EntityType.Manga,
                    UserId     = userId,
                    CreateTime = DateTime.Now
                };
                await favoriteService.Insert(favorite);

                context.CommitTran();
                return(true);
            }
            catch (Exception e)
            {
                context.RollbackTran();
                throw;
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async ValueTask <bool> RemoveMangaFavorite(long userId, long mangaId)
        {
            using var context = Context;
            var favoriteService = new FavoriteService(context);

            context.BeginTran();
            try
            {
                if (await favoriteService.DeleteAsync(it => it.EntityId == mangaId && it.UserId == userId))
                {
                    context.CommitTran();
                    return(true);
                }
                context.RollbackTran();
                return(false);
            }
            catch (Exception e)
            {
                context.RollbackTran();
                throw;
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }