public async Task <ActionResult <IEnumerable <object> > > Get(int id, int?offset)
        {
            _logger.LogDebug($"Getting articles for feed {id} from db, using client UTC offset {offset}");

            var loggedInUser = await _userAccountRepository.FindOrCreateAsync(User);

            var feed = await _userFeedRepository.GetByIdAsync(id);

            var readArticles = await _userArticlesReadRepository.GetByUserFeedIdAsync(feed.Id);

            IEnumerable <Article> articles;

            if (loggedInUser.ShowAllItems)
            {
                articles = await _articleRepository.GetByRssFeedIdAsync(feed.RssFeedId);
            }
            else
            {
                articles = await _articleRepository.GetByRssFeedIdAsync(feed.RssFeedId, readArticles);
            }

            return(articles
                   .OrderBy(a => a.Published)
                   .Select(a => new { read = readArticles.Any(uar => uar.ArticleId == a.Id), feed = id, story = a.Id, heading = a.Heading, article = HtmlPreview.Preview(a.Body), posted = FriendlyDate.ToString(a.Published, offset) })
                   .ToList());
        }
        public async Task <ActionResult <IEnumerable <object> > > PostAsync([FromForm] ArticleReadViewModel feed)
        {
            _logger.LogDebug($"Marking story [{feed.StoryId}] as {(feed.Read ? "read" : "unread")} for feed {feed.FeedId}");

            var newArticles = new List <Article>();

            var userAccount = await _userAccountRepository.FindOrCreateAsync(User);

            var userFeedId = 0;

            if (feed.FeedId.HasValue && !feed.StoryId.HasValue)
            {
                if (!feed.MaxStoryId.HasValue || feed.MaxStoryId.Value <= 0)
                {
                    feed.MaxStoryId = int.MaxValue;
                }

                _logger.LogDebug($"Marking all stories as {(feed.Read ? "read" : "unread")}: {feed.FeedId} up to id {feed.MaxStoryId}");
                userFeedId = feed.FeedId.Value;

                var feedToMarkAllAsRead = await _userFeedRepository.GetByIdAsync(feed.FeedId.Value);

                if (feedToMarkAllAsRead != null && feedToMarkAllAsRead.UserAccountId == userAccount.Id)
                {
                    foreach (var article in await _articleRepository.FindUnreadArticlesInUserFeedAsync(feedToMarkAllAsRead))
                    {
                        if (article.Id > feed.MaxStoryId)
                        {
                            newArticles.Add(article);
                            continue;
                        }
                        await MarkAsAsync(feedToMarkAllAsRead, article.Id, feed.Read);
                    }
                }
            }
            else if (feed.StoryId.HasValue)
            {
                var article = await _articleRepository.GetByIdAsync(feed.StoryId.Value);

                var feedToMarkAsRead = (await _userFeedRepository.GetAllByUserAndRssFeedAsync(userAccount, article.RssFeedId)).FirstOrDefault();
                if (feedToMarkAsRead != null)
                {
                    userFeedId = feedToMarkAsRead.Id;
                    await MarkAsAsync(feedToMarkAsRead, article.Id, feed.Read);
                }
                else
                {
                    _logger.LogWarning($"Feed {feed.FeedId} could not be found or is not associated with the current user, will not make any changes");
                }
            }

            return(newArticles
                   .OrderBy(a => a.Published)
                   .Select(a => new { read = false, feed = userFeedId, story = a.Id, heading = a.Heading, article = HtmlPreview.Preview(a.Body), posted = FriendlyDate.ToString(a.Published, feed.OffsetId) })
                   .ToList());
        }