Example #1
0
        public static async Task <Guid> CreateQuizAsync(this HttpClient client, CreateQuizRequest request)
        {
            var response = await client.PostAsync("api/v1/quiz/new", request.ToJsonContent());

            var content = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <CreateQuizResponse>(content).QuizId);
        }
Example #2
0
        public async Task <CreateQuizResponse> CreateQuiz([FromBody] CreateQuizRequest request)
        {
            string id = await quizService.Create(request);

            return(new CreateQuizResponse
            {
                Id = id,
            });
        }
Example #3
0
        public async Task <ActionResult <CreateQuizResponse> > CreateNewQuiz(
            [FromServices] IUnitOfWork unitOfWork,
            [FromBody] CreateQuizRequest request)
        {
            try
            {
                var createdQuiz = await TaskManager.AddQuizAsync(unitOfWork, request.QuizName, request.Tasks);

                return(Ok(new CreateQuizResponse
                {
                    QuizId = createdQuiz.QuizId
                }));
            }
            catch (TaskNotFoundException)
            {
                return(NotFound("one or more tasks not found"));
            }
        }
Example #4
0
        public override async Task <Empty> CreateQuiz(CreateQuizRequest request, ServerCallContext context)
        {
            await _context.Quiz.AddAsync(new Domain.Entities.Quiz()
            {
                Title       = request.Title,
                Description = request.Description,
                Questions   = request.Questions.Select(x => new Question()
                {
                    Title   = x.Title,
                    Timeout = x.Timeout,
                    Answer  = x.Answers.Select(y => new Answer()
                    {
                        IsCorrect = y.IsCorrect
                    }).ToList()
                }).ToList()
            });

            await _context.SaveChangesAsync();

            return(new Empty());
        }