public async Task <IActionResult> DeleteTag(Guid id)
        {
            var model = new TagDeleteDto()
            {
                Id = id
            };
            await _tagService.DeleteAsync(model);

            return(NoContent());
        }
示例#2
0
        public async Task DeleteAsync(TagDeleteDto dto)
        {
            if (dto.Id == Guid.Empty)
            {
                throw new ArticleException(ArticleErrorCodes.TagIdCannotBeNull, "Tag Id field is mandatory.", dto);
            }

            var entity = await _tagRepository.GetByIdAsync(dto.Id);

            if (entity == null)
            {
                throw new ArticleException(ArticleErrorCodes.TagCouldNotBeFound, "Tag could not be found.", dto);
            }

            if (entity.ArticleTags != null && entity.ArticleTags.Any())
            {
                throw new ArticleException(ArticleErrorCodes.TagCannotBeDelete, "Tag Cannot Be Deleted because an article is related.", dto);
            }

            await _tagRepository.DeleteAsync(entity);
        }