Beispiel #1
0
        public ActionResult Login([FromBody] UserLogin user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var quizUsers = _context.QuizUsers.Where(u => u.UserName == user.UserName).ToList();

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

            QuizUsers quizUser = quizUsers[0];

            string suppliedHasedPassword = Security.GetSaltedHashPassword(quizUser.Salt, user.UserPassword);
            string actualHashedPassword  = quizUser.UserPassword;

            if (!(suppliedHasedPassword.Equals(actualHashedPassword)))
            {
                return(BadRequest(ReturnResponse.GetFailureStatus(ModelState)));
            }

            //ReturnResponse response = new ReturnResponse();
            //ReturnStatus status = new ReturnStatus();
            //status.Code = "1";
            //status.Message = "Success";

            //response.Result = quizUser; //GetUserToRespond(quizUser);
            //response.Status = status;

            return(Ok(ReturnResponse.GetSuccessStatus(quizUser)));
        }
Beispiel #2
0
        public IActionResult Update([FromBody] Question question)
        {
            if (question == null || question.options == null || question.questionType == null)
            {
                return(BadRequest(ReturnResponse.GetFailureStatus("Bad Request")));
            }

            int newQuestionId = _repository.UpdateQuestion(question);

            if (newQuestionId > 0)
            {
                return(Ok(ReturnResponse.GetSuccessStatus("Successfully Inserted: new id is: " + newQuestionId.ToString())));
            }
            else
            {
                return(BadRequest("Failed to insert the question"));
            }
        }
Beispiel #3
0
        public IActionResult add([FromBody] Question question)
        {
            if (question == null || question.options == null || question.questionType == null)
            {
                return(BadRequest(ReturnResponse.GetFailureStatus("Bad Request")));
            }

            QuizQuestions ques = new QuizQuestions();

            ques.Description    = question.name;
            ques.AccountId      = question.accountId;
            ques.ClassSubjectId = question.classSubjectId;

            _context.QuizQuestions.Add(ques);
            _context.SaveChanges();

            int  newQuestionId   = ques.Id;
            long correctAnswerId = 0;

            foreach (Option o in question.options)
            {
                QuizQuestionsOptions opt = new QuizQuestionsOptions();
                opt.Description = o.name;
                opt.QuestionId  = newQuestionId;

                _context.QuizQuestionsOptions.Add(opt);
                _context.SaveChanges();

                if (o.isAnswer)
                {
                    correctAnswerId = opt.Id;
                }
            }


            ques.CorrectAnswerOptionId = correctAnswerId;

            _context.QuizQuestions.Update(ques);
            _context.SaveChanges();

            return(Ok(ReturnResponse.GetSuccessStatus("Successfully Inserted: new id is: " + newQuestionId.ToString())));
        }