// [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 <IActionResult> Delete(int id)
        {
            var topicCommentFromRepo = await _topicRepo.GetTopicComment(id);

            if (topicCommentFromRepo == null)
            {
                return(NotFound());
            }

            if (!await this.MatchAppUserWithToken(topicCommentFromRepo.AppUserId.GetValueOrDefault()))
            {
                return(Unauthorized());
            }

            _topicRepo.Delete(topicCommentFromRepo);

            if (await _topicRepo.SaveAll() > 0)
            {
                return(Ok());
            }

            return(BadRequest("トピック候補の削除に失敗しました"));
        }
        public async Task <IActionResult> Delete(int memberId, int commentId)
        {
            var topicCommentFromRepo = await _topicRepo.GetCommentFeel(memberId, commentId);

            if (topicCommentFromRepo == null)
            {
                return(NotFound());
            }

            if (!await this.MatchAppUserWithToken(topicCommentFromRepo.AppUserId))
            {
                return(Unauthorized());
            }

            _topicRepo.Delete(topicCommentFromRepo);

            if (await _topicRepo.SaveAll() > 0)
            {
                return(Ok());
            }

            return(BadRequest("コメント反応の削除に失敗しました"));
        }
Example #4
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);
        }