예제 #1
0
        public async Task CreateFaq(Faq faq)
        {
            FaqEntity newFaq = new FaqEntity
            {
                Content     = faq.Content,
                CreatedDate = DateTime.Now,
                Creator     = faq.Creator,
                Tag         = faq.Tag
            };

            await _db.AddAsync(newFaq);

            await _db.SaveChangesAsync();
        }
예제 #2
0
        public async Task <ActionResult <Question> > Like(int id)
        {
            if (id == default)
            {
                return(NotFound());
            }

            var question = await _context.Questions.FindAsync(id);

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

            question.Likes = question.Likes + 1;

            _context.Questions.Update(question);
            await _context.SaveChangesAsync();

            return(question);
        }
예제 #3
0
        public async Task <FAQ> CreateAsync(FAQ faq)
        {
            if (faq == null)
            {
                throw new ArgumentNullException(nameof(faq));
            }

            var dbFaq = new Data.Models.Faq
            {
                Answer   = faq.Answer,
                Question = faq.Question,
            };

            _dbContext.Faqs.Add(dbFaq);
            await _dbContext.SaveChangesAsync();

            return(new FAQ
            {
                Answer = dbFaq.Answer,
                Question = dbFaq.Question,
                Id = dbFaq.Id
            });
        }
        public async Task Handle(ReminderSentEvent notification, CancellationToken cancellationToken)
        {
            if (!notification.QuestionIds.Any())
            {
                return;
            }

            var questions = await _dbContext.Questions.AsQueryable()
                            .Where(x => notification.QuestionIds.Contains(x.Id))
                            .ToListAsync(cancellationToken);

            questions.ForEach(x => x.Meta.ReminderAt = null);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
        /// <inheritdoc />
        public async Task Handle(AnswerNotFoundEvent notification, CancellationToken cancellationToken)
        {
            if (!_options.SelfServiceEnabled)
            {
                return;
            }


            var question = new Question(notification.QuestionMessage.Content,
                                        notification.QuestionMessage.Author.Id,
                                        notification.QuestionMessage.Id,
                                        _options.ReminderThreshold);

            await _dbContext.Questions.AddAsync(question, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
예제 #6
0
        public async Task Handle(MessageWithReferenceReceivedEvent notification, CancellationToken cancellationToken)
        {
            var(userMessage, referencedMessage) = notification;

            var question = await _dbContext.Questions.
                           FirstOrDefaultAsync(x => x.Meta.MessageId == referencedMessage.Id,
                                               cancellationToken);

            if (question is null)
            {
                return;
            }

            question.Answer = new Answer(userMessage.Content, userMessage.Id, userMessage.Author.Id);
            await _dbContext.SaveChangesAsync(cancellationToken);

            _logger.LogInformation("Answer contributed to question {QuestionId} by {UserId}",
                                   question.Id, userMessage.Author.Id);
            _telemetryClient.TrackEvent("Answer contributed");

            await _mediator.Publish(new AnswerAddedToQuestionEvent(question.Id), cancellationToken);
        }