private async Task DeleteTag(Tag tag)
        {
            var result = await _tagBL.DeleteTagByTagId(tag.TagId);

            if (result.Details.ResultStatus == ResultStatus.Success)
            {
                var deletedTagId = result.Data;
                _logger.LogInformation("Deleted tag {tagId}", deletedTagId);
            }
            else
            {
                _logger.LogWarning("Tried to delete tag {@tag} but there was a problem.", tag);
            }
        }
Пример #2
0
        private async Task RenameTagJobAsync(string uniqueKey, TagResult workingTag, string newTagId)
        {
            try
            {
                await _jobStatusNotifier.PushRenameTagJobStatusUpdate(uniqueKey, workingTag, JobStage.InProgress);

                // below is only needed if the current tag is null (not in DB) for some reason. update Projects / Blog Posts createsOrFinds any NEW tag
                var currentTagId    = workingTag.Data.TagId;
                var currentTagCount = workingTag.Data.ArticleCount;

                var projectsChangedCount = await RenameTagInProjects(currentTagId, newTagId);

                var blogPostsChangedCount = await RenameTagInBlogPosts(currentTagId, newTagId);

                var deletedTagId = await _tagBL.DeleteTagByTagId(currentTagId);

                var newTagResult = await _tagBL.CreateOrFindByTagId(newTagId);

                // newTagResult.Details.Message =
                //     $@"{currentTagId} with {currentTagCount} articles was renamed to {newTagId}. It now has {newTagResult.Data.ArticleCount} articles. Projects count: {projectsChangedCount}. Blog Posts count: {blogPostsChangedCount}.";
                newTagResult.Details.Message = workingTag.Data.TagId;
                await _jobStatusNotifier.PushRenameTagJobStatusUpdate(uniqueKey, newTagResult, JobStage.Done);
            }
            catch (Exception exception)
            {
                var currentTagId = workingTag.Data.TagId;
                _logger.LogError(exception, "There was a problem renaming {tagId}", currentTagId);
                var result = new TagResult
                {
                    Details = new ResultDetails
                    {
                        ResultStatus = ResultStatus.Failure,
                        Message      = $"There was a problem renaming {currentTagId} to {newTagId}."
                    }
                };
                await _jobStatusNotifier.PushRenameTagJobStatusUpdate(uniqueKey, result, JobStage.Error);
            }
        }