Пример #1
0
        public async ValueTask <bool> DeleteTagType(long tagTypeId)
        {
            using var context = Context;
            var mangaTagMappingService = new MangaTagMappingService(context);
            var tagService             = new TagService(context);
            var tagTypeService         = new TagTypeService(context);

            try
            {
                context.BeginTran();

                var tags = await tagService.GetListAsync(it => it.TypeId == tagTypeId);

                var keys = tags.Select(it => it.Key).ToList();
                await mangaTagMappingService.DeleteAsync(it => keys.Contains(it.TagId));

                await tagService.DeleteAsync(it => it.TypeId == tagTypeId);

                await tagTypeService.DeleteAsync(it => it.ObjectId == tagTypeId);

                context.CommitTran();
                return(true);
            }
            catch (Exception e)
            {
                context.RollbackTran();
                throw;
            }
        }
Пример #2
0
        public async ValueTask <List <TagType> > GetTagTypes()
        {
            using var context = Context;
            var tagTypeService = new TagTypeService(context);

            return(await tagTypeService.GetAllTagTypes());
        }
Пример #3
0
        public async ValueTask <List <Tag> > Insert(List <Tag> tags)
        {
            if (tags == null || tags.Count <= 0)
            {
                return(null);
            }
            foreach (var tag in tags)
            {
                DataFormatter.Format(tag);
            }
            var context        = Context;
            var tagTypeService = new TagTypeService(context);
            var tagService     = new TagService(context);

            try
            {
                context.BeginTran();
                await tagTypeService.Insert(tags.Select(it => it.Type).Distinct().ToList());

                var tagType = (await tagTypeService
                               .GetTagTypes(tags.Select(it => it.Type.Name).Distinct().ToList()))
                              .ToDictionary(it => it.Name, it => it);

                foreach (var tag in tags)
                {
                    tag.Type   = tagType[tag.Type.Name];
                    tag.TypeId = tag.Type.ObjectId;
                }

                var result = await tagService.Insert(tags);

                FtsIndexService.CreateFtsIndex(result.InsertList.Select(it => it.Item).ToList());
                var realTags = await tagService.GetTags(tags.Select(it => new Tuple <long, string>(it.TypeId, it.Name)).ToList());

                context.CommitTran();
                return(realTags);
            }
            catch (Exception e)
            {
                context.RollbackTran();
                throw;
            }
        }
Пример #4
0
        public async ValueTask <long> Insert(TagType tagType)
        {
            DataFormatter.Format(tagType);
            using var context = Context;
            try
            {
                context.BeginTran();
                var tagTypeService = new TagTypeService(context);
                var success        = await tagTypeService.InsertAsync(tagType);

                context.CommitTran();
                return(tagType.ObjectId);
            }
            catch (Exception e)
            {
                context.RollbackTran();
                throw;
            }
        }