public async Task <IActionResult> CreateAsync(ArticleHit entity)
        {
            await _applicationDbContext.Set <ArticleHit>().AddAsync(entity);

            await _applicationDbContext.SaveChangesAsync();

            _mostViewedArticleService.MostViewedArticles = MostViewedArticleHostedService.GetMostViewedArticles(_applicationDbContext);
            return(Ok(entity));
        }
Пример #2
0
        public async Task SendHitRequest(int id)
        {
            var article = _db.Articles.Find(id);

            if (article != null)
            {
                var content = new ArticleHit
                {
                    ArticleId  = article.Id,
                    Created    = DateTimeOffset.Now,
                    LastUpdate = DateTimeOffset.Now
                };
                var json = JsonConvert.SerializeObject(content);
                var data = new StringContent(json, Encoding.UTF8, "application/json");

                var url = "https://localhost:44382/api/ArticleHit/create-async";
                using var client = new HttpClient();

                await client.PostAsync(url, data);
            }
        }