Ejemplo n.º 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)));
        }
Ejemplo n.º 2
0
        public IActionResult GetAllClassesSubjectsByAccountId(int accountId)
        {
            List <QuestionAvailaleClassAndSubject> list = _repository.GetAllClassesSubjectsByAccountId(accountId);

            if (list != null && list.Count > 0)
            {
                return(Ok(ReturnResponse.GetSuccessStatus(list)));
            }
            else
            {
                return(NotFound(ReturnResponse.Get(ReturnConstant.CLASS_SUBJECT_ALL_NOT_FOUND)));
            }
        }
Ejemplo n.º 3
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"));
            }
        }
Ejemplo n.º 4
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())));
        }