Exemplo n.º 1
0
        public async Task <object> UpdateAsync(
            [FromBody] WriteNewsItemRequest body)
        {
            var newsItem = await _newsItemRepository.GetAsync(body.Id);

            if (newsItem == null)
            {
                return(NotFound(JResponse.Error("News item not found.")));
            }

            newsItem.Modified = DateTime.UtcNow;
            if (body.Title != null)
            {
                newsItem.Title = body.Title;
            }
            if (body.Html != null)
            {
                newsItem.Html = body.Html;
            }
            if (body.Published == true)
            {
                newsItem.Published = DateTime.UtcNow;
            }
            _logger.LogInformation($"Updating news item: {newsItem.Title} (updated by {User.Identity.Name}");
            await _newsItemRepository.UpdateAsync(newsItem);

            return(JResponse.OK());
        }