public async Task <UnifyResponseDto> UploadTagByJson()
        {
            string tagPath = Path.Combine(_hostingEnv.WebRootPath, "json-tag.json");
            string text    = System.IO.File.ReadAllText(tagPath);

            JObject json = JsonConvert.DeserializeObject <JObject>(text);

            foreach (var tag in json["d"]["tags"])
            {
                string tagName = tag["title"].ToString();
                bool   valid   = await _tagAuditBaseRepository.Where(r => r.TagName == tagName).AnyAsync();

                if (valid)
                {
                    Console.WriteLine($"{tagName}已存在,不需要生成");
                    continue;
                }

                FileDto fileDto = this.UploadToQiniu(tag["icon"].ToString());

                var tagEntity = new CreateUpdateTagDto()
                {
                    TagName   = tagName,
                    Alias     = tag["alias"].ToString(),
                    Status    = true,
                    Thumbnail = fileDto.Path
                };
                await _tagService.CreateAsync(tagEntity);
            }

            return(UnifyResponseDto.Success());
        }
Ejemplo n.º 2
0
        public async Task CreateAsync(CreateUpdateTagDto createTag)
        {
            bool exist = await _tagRepository.Select.AnyAsync(r => r.TagName == createTag.TagName);

            if (exist)
            {
                throw new LinCmsException($"标签[{createTag.TagName}]已存在");
            }

            Tag tag = _mapper.Map <Tag>(createTag);
            await _tagRepository.InsertAsync(tag);
        }
Ejemplo n.º 3
0
        public ResultDto Post([FromBody] CreateUpdateTagDto createTag)
        {
            bool exist = _tagRepository.Select.Any(r => r.TagName == createTag.TagName);

            if (exist)
            {
                throw new LinCmsException($"标签[{createTag.TagName}]已存在");
            }

            Tag tag = _mapper.Map <Tag>(createTag);

            _tagRepository.Insert(tag);
            return(ResultDto.Success("新建标签成功"));
        }
Ejemplo n.º 4
0
        public async Task UpdateAsync(Guid id, CreateUpdateTagDto updateTag)
        {
            Tag tag = await _tagRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (tag == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = await _tagRepository.Select.AnyAsync(r => r.TagName == updateTag.TagName && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"标签[{updateTag.TagName}]已存在");
            }

            _mapper.Map(updateTag, tag);
            await _tagRepository.UpdateAsync(tag);
        }
Ejemplo n.º 5
0
        public ResultDto Put(Guid id, [FromBody] CreateUpdateTagDto updateTag)
        {
            Tag tag = _tagRepository.Select.Where(r => r.Id == id).ToOne();

            if (tag == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = _tagRepository.Select.Any(r => r.TagName == updateTag.TagName && r.Id != id);

            if (exist)
            {
                throw new LinCmsException($"标签[{updateTag.TagName}]已存在");
            }

            _mapper.Map(updateTag, tag);

            _tagRepository.Update(tag);

            return(ResultDto.Success("更新标签成功"));
        }
Ejemplo n.º 6
0
        public async Task <UnifyResponseDto> UpdateAsync(Guid id, [FromBody] CreateUpdateTagDto updateTag)
        {
            await _tagService.UpdateAsync(id, updateTag);

            return(UnifyResponseDto.Success("更新标签成功"));
        }
Ejemplo n.º 7
0
        public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateUpdateTagDto createTag)
        {
            await _tagService.CreateAsync(createTag);

            return(UnifyResponseDto.Success("新建标签成功"));
        }