コード例 #1
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            _quizContext.Questions.Add(question);
            await _quizContext.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] Models.Question question)
        {
            context.questions.Add(question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #3
0
        public async Task <IActionResult> PutQuiz([FromRoute] int id, [FromBody] Quiz quiz)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogError("Put Quiz: Bad Model");
                return(BadRequest(ModelState));
            }

            if (id != quiz.ID)
            {
                return(BadRequest());
            }

            _context.Entry(quiz).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuizExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public async Task <IActionResult> PutQuiz(int id, Quiz quiz)
        {
            if (id != quiz.ID)
            {
                return(BadRequest());
            }

            _context.Entry(quiz).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuizExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #5
0
        public async Task <IActionResult> PutQuestion([FromRoute] int id, [FromBody] Question question)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != question.Id)
            {
                return(BadRequest());
            }


            _context.Entry(question).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(id));
        }
コード例 #6
0
        public async Task <IActionResult> PutQuestion(int id, QuestionsDTO questionDto)
        {
            if (id != questionDto.Id)
            {
                return(BadRequest());
            }

            var question = MapFromDataModel(questionDto);

            _context.Entry(question).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #7
0
        public async Task <IActionResult> UpdateQuestion(int id, string _question, string answer1,
                                                         string answer2, string answer3, string rightAnswer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var question = await _context.Questions.SingleOrDefaultAsync(m => m.Id == id);

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

            question.Id          = id;
            question._question   = _question;
            question.Answer1     = answer1;
            question.Answer2     = answer2;
            question.Answer3     = answer3;
            question.RightAnswer = rightAnswer;


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

            return(Ok(question));
        }
コード例 #8
0
        private async void BtnGenerate_Click(object sender, RoutedEventArgs e)
        {
            tbOutput.Text         = "Generating...";
            btnGenerate.IsEnabled = false;

            Random rand = new Random();

            _quizcontext.Quizzes.RemoveRange(_quizcontext.Quizzes);
            await _quizcontext.SaveChangesAsync();

            for (int i = 0; i < 10; i++)
            {
                var quiz = new Quiz()
                {
                    Question   = $"Loerm {i}",
                    Answer     = ((char)rand.Next(0x41, 0x44)).ToString(),
                    Key        = i + 1,
                    Selections = new List <string>()
                    {
                        "Answer 1",
                        "Answer 2",
                        rand.NextDouble() > 0.5? "Answer 3":null,
                        rand.NextDouble() > 0.5? "Answer 4":null,
                    }
                };
                await _quizcontext.Quizzes.AddAsync(quiz);
            }
            await _quizcontext.SaveChangesAsync();

            tbOutput.Text         = "Quiz generated.";
            btnGenerate.IsEnabled = true;
        }
コード例 #9
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            context.Questions.Add(question);
            Console.WriteLine(question.question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #10
0
        public async Task <T> CreateAsync(T model)
        {
            await _context.Set <T>().AddAsync(model);

            await _context.SaveChangesAsync();

            return(model);
        }
コード例 #11
0
        public async Task <IActionResult> Post([FromBody] Quiz quiz)
        {
            _context.Quizzes.Add(quiz);

            await _context.SaveChangesAsync();

            return(Ok(quiz));
        }
コード例 #12
0
        public async Task <ActionResult <QuestionDto> > Post([FromBody] QuestionDto value)
        {
            var question = mapper.Map <Question>(value);
            await context.Questions.AddAsync(question);

            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #13
0
        public async Task <IActionResult> Post([FromBody] Models.Question question)
        {
            var quiz = context.Quiz.SingleOrDefault(q => q.ID == question.QuizId);

            if (quiz == null)
            {
                return(NotFound());
            }
            context.Questions.Add(question); await context.SaveChangesAsync(); return(Ok(question));
        }
コード例 #14
0
ファイル: QuizzesController.cs プロジェクト: JabiDH/PlayQuiz
        public async Task <IActionResult> Post([FromBody] Quiz quiz)
        {
            var userId = HttpContext.User.Claims.First().Value;

            quiz.OwnerId = userId;
            context.Quizzes.Add(quiz);
            await context.SaveChangesAsync();

            return(Ok(quiz));
        }
コード例 #15
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #16
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Senha,Foto")] Jogador jogador)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jogador);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(jogador));
        }
コード例 #17
0
        public async Task <IActionResult> Create([Bind("Id,Pergunta,Opcao_a,Opcao_b,Opcao_c,Opcao_d,Resposta_certa")] Questao questao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(questao);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(questao));
        }
コード例 #18
0
        public async Task <IActionResult> Post([FromBody] Models.Question question)
        {
            if (!context.Quizzes.Any(q => q.ID == question.QuizId))
            {
                return(StatusCode(404));
            }
            context.Questions.Add(question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #19
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            if (!context.Quiz.Any(q => q.ID == question.QuizId)) //check if there is existing quiz
            {
                return(NotFound());
            }
            context.Questions.Add(question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #20
0
      public async Task <IActionResult> Put(int id, [FromBody] Models.Question question)
      {
          if (id != question.ID)
          {
              return(BadRequest());
          }
          context.Entry(question).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
          await context.SaveChangesAsync();

          return(Ok(question));
      }
コード例 #21
0
ファイル: QuizController.cs プロジェクト: umair-gujjar/quiz
        public async Task Answer([FromBody] Model.QuestionAnswer answer)
        {
            var answeredOption = await _quizContext.Set <QuestionOption>()
                                 .FirstOrDefaultAsync(x => x.Id == answer.Option);

            if (answeredOption != null)
            {
                answeredOption.Result = answer.Result;
                await _quizContext.SaveChangesAsync();
            }
        }
コード例 #22
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            if (context.Quiz.Find(question.QuizId) == null)
            {
                return(NotFound());
            }

            context.Questions.Add(question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #23
0
        public async Task <ActionResult> Create([Bind(Include = "LanguageId,LanguageName")] LanguageMaster languageMaster)
        {
            if (ModelState.IsValid)
            {
                db.LanguageMasters.Add(languageMaster);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(languageMaster));
        }
コード例 #24
0
        public async Task <IActionResult> Create([Bind("Id,Statement,CategoryId")] Question question)
        {
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", question.CategoryId);
            return(View(question));
        }
コード例 #25
0
        public async Task <IActionResult> PutQuiz(int id, Quiz quiz)
        {
            if (id != quiz.ID)
            {
                return(BadRequest());
            }

            _context.Entry(quiz).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(quiz));
        }
コード例 #26
0
        public async Task <IActionResult> Create([Bind("Id,JogadorId,QuestaoId,Resposta")] RespostaJogador respostaJogador)
        {
            if (ModelState.IsValid)
            {
                _context.Add(respostaJogador);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["JogadorId"] = new SelectList(_context.Jogador, "Id", "Id", respostaJogador.JogadorId);
            ViewData["QuestaoId"] = new SelectList(_context.Questao, "Id", "Id", respostaJogador.QuestaoId);
            return(View(respostaJogador));
        }
コード例 #27
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            var quiz = context.Quiz.Where(c => c.ID == question.QuizId);

            if (quiz == null)
            {
                return(NotFound());
            }
            context.Questions.Add(question);
            await context.SaveChangesAsync();

            return(Ok(question));
        }
コード例 #28
0
        public async Task <ActionResult> Create([Bind(Include = "ExamId,ExamName,CertificationId")] Exam exam)
        {
            if (ModelState.IsValid)
            {
                db.Exams.Add(exam);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CertificationId = new SelectList(db.Certifications, "CertificationId", "CertificationName", exam.CertificationId);
            return(View(exam));
        }
コード例 #29
0
        public async Task <ActionResult> Create([Bind(Include = "JobID,JobTitle,CountryId,JobAreaId,JobLocation,CompanyName,EmploymentType,MonthlySalary,Benefits,MinimumWorkExperience,MinimumEducationLevel,ListedBy,CompanySize,CareerLevel,Description,Skills,EmailID,ContactPerson,PhoneNumber,Country,JobCategory,PostedDate,LasteDate,IsActive")] JobVaccancy jobVaccancy)
        {
            if (ModelState.IsValid)
            {
                db.JobVaccancys.Add(jobVaccancy);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CountryId = new SelectList(db.CountryMasters, "CountryId", "CountryName", jobVaccancy.CountryId);
            ViewBag.JobAreaId = new SelectList(db.JobFieldAreas, "JobAreaId", "JobAreaName", jobVaccancy.JobAreaId);
            return(View(jobVaccancy));
        }
コード例 #30
0
        public async Task <IActionResult> Post([FromBody] Question question)
        {
            var quiz = _context.Set <Quiz>().SingleOrDefault(q => q.Id == question.QuizId);

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

            _context.Set <Question>().Add(question);
            await _context.SaveChangesAsync();

            return(Ok(question));
        }