Пример #1
0
        public async Task <ActionResult <QuestionDto> > Get(string uuid, CancellationToken ct)
        {
            Question question;

            try
            {
                question = await _context.Questions
                           .SingleOrDefaultAsync(q => q.Uuid == uuid, ct);
            }
            catch (Exception ex)
            {
                _logger.LogError(EventIds.DatabaseError, ex, ex.Message);
                throw;
            }

            if (question == null)
            {
                return(NotFound());
            }
            return(QuestionDto.FromQuestion(question));
        }
Пример #2
0
        public async Task <IActionResult> Ask(string place, string presenter, string slug, int slide,
                                              [FromBody] QuestionDto dto, CancellationToken ct)
        {
            var showIdentifier = ShowIdentifier(place, presenter, slug);
            var from           = User.FindFirstValue(DeckHubClaimTypes.Handle);

            if (string.IsNullOrEmpty(from))
            {
                return(Forbid());
            }

            var question = new Question
            {
                Uuid  = Guid.NewGuid().ToString(),
                Show  = showIdentifier,
                Slide = slide,
                Text  = dto.Text,
                From  = from,
                Time  = dto.Time
            };

            try
            {
                _context.Questions.Add(question);
                await _context.SaveChangesAsync(ct);

                _redis.PublishQuestion(question);
            }
            catch (Exception ex)
            {
                _logger.LogError(EventIds.DatabaseError, ex, ex.Message);
                throw;
            }

            return(CreatedAtAction("Get", new { uuid = question.Uuid }, QuestionDto.FromQuestion(question)));
        }