Exemple #1
0
        public async Task <string> CreateArticleAsync()
        {
            var id = await articleRepository.InsertAsync(new ArticleModel());

            await cache.RemoveSaveAsync(CacheKeys.AllArticles.Name);

            await cache.RemoveSaveAsync(CacheKeys.AllPublishedArticles.Name);

            return(id);
        }
Exemple #2
0
        public async Task UpdateTagsForArticelAsync(SaveArticleDto model)
        {
            await tagRepository.UpdateTagsForArticle(model.Tags, model.Article.Id);

            await cache.RemoveSaveAsync(CacheKeys.AllDistinctTags.Name);

            await cache.RemoveSaveAsync(CacheKeys.AllPublishedTags.Name);

            await cache.RemoveSaveAsync(CacheKeys.AllDistinctPublishedTags.Name);

            await cache.RemoveSaveAsync(CacheKeys.AllTags.Name);

            await cache.RemoveSaveAsync(CacheKeys.TagsByArticleId.Name(model.Article.Id));
        }
Exemple #3
0
        public async Task AddAsync(string name, Stream data)
        {
            using var buffer = new MemoryStream();
            await data.CopyToAsync(buffer);

            var image = new ImageModel
            {
                Name = name,
                Data = Convert.ToBase64String(buffer.ToArray()),
                Type = $"image/{name.Substring(name.LastIndexOf(".") + 1)}"
            };

            await imageRepository.InsertOrUpdate(image);

            await cache.RemoveSaveAsync(CacheKeys.Image.Name(name));

            await cache.RemoveSaveAsync(CacheKeys.AllImages.Name);
        }
Exemple #4
0
        public async Task InsertCommentAsync(CreateCommentDto model)
        {
            using var activity = traceActivityDecorator.StartActivity();

            var dbModel = mapper.Map <CommentModel>(model);

            dbModel.Date = DateTime.UtcNow;

            await commentRepository.InsertAsync(dbModel);

            await cache.RemoveSaveAsync(CacheKeys.AllComments.Name);

            await cache.RemoveSaveAsync(CacheKeys.CommentsByArticleId.Name(model.ArticleId));

            var tags = new[] {
                new KeyValuePair <string, object>("user", model.User)
            }.Concat(MetricTags.GetDefaultTags()).ToArray();

            CommmentCreatedCounter.Add(1, tags);

            await messageBus.SendMessageAsync("ntfrex.blog.comments", JsonSerializer.Serialize(model));
        }