// [Authorize(Roles = "Administrator")]
        public async Task <ActionResult> ChangeTodaysTopic()
        {
            var oldTopic = await _topicRepo.GetActiveDailyTopic();

            if (oldTopic != null)
            {
                if (oldTopic.IsTemporary)
                {
                    _topicRepo.Delete(oldTopic);
                }
                else
                {
                    _topicRepo.ResetTopicLikes(oldTopic.Id);
                    oldTopic.LastDiscussed = DateTime.Now;
                    oldTopic.IsActive      = false;
                }
            }
            await _topicRepo.SaveAll();

            var newTopic = await _topicRepo.GetTopDailyTopic();

            if (newTopic == null)
            {
                newTopic = await _topicRepo.GetOldestDailyTopic();
            }

            newTopic.IsActive = true;

            _topicRepo.ResetTopicComments();
            await _topicRepo.SaveAll();

            return(Ok("New Topic " + newTopic.Title));
        }
Example #2
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("Cron Task - ChangeTopicTask");
            _logger.LogInformation("Cron Task - ChangeTopicTask");
            var oldTopic = await _repo.GetActiveDailyTopic();

            if (oldTopic != null)
            {
                if (oldTopic.IsTemporary)
                {
                    _repo.Delete(oldTopic);
                }
                else
                {
                    oldTopic.LastDiscussed = DateTime.Now;
                    oldTopic.IsActive      = false;
                }
                _repo.ResetTopicLikes(oldTopic.Id);
            }
            await _repo.SaveAll();

            var newTopic = await _repo.GetTopDailyTopic();

            if (newTopic == null)
            {
                newTopic = await _repo.GetOldestDailyTopic();
            }

            newTopic.IsActive = true;

            _repo.ResetTopicComments();
            await _repo.SaveAll();

            Console.WriteLine("End ChangeTopicTask Old Topic:" + oldTopic.Title + " -> New Topic:" + newTopic.Title);
            _logger.LogInformation("End ChangeTopicTask Old Topic:" + oldTopic.Title + " -> New Topic:" + newTopic.Title);
        }