public bool IsCorrect([FromBody] PostQuestionRequest request) { Question q = FindQuestion(request.question); if (request.answer == q.Answer) { return(true); } else { return(false); } }
protected async void Submit_Exam(object sender, EventArgs e) { int score = 0; for (int i = 0; i < questions.Count; i++) { RadioButtonList ans = (RadioButtonList)this.Master.FindControl("MainContent").FindControl("que" + i.ToString()); Question q = questions[i]; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); PostQuestionRequest postQuestionRequest = new PostQuestionRequest { question = q.QuestionVal, answer = ans.SelectedValue }; HttpResponseMessage response = await client.PostAsJsonAsync("api/question/is-correct", postQuestionRequest); if (response.IsSuccessStatusCode) { bool iscrt = bool.Parse(response.Content.ReadAsStringAsync().Result); if (iscrt) { score++; } } } //bool iscrt = questionServiceClient.IsCorrect(q.QuestionVal, ans.SelectedValue); //if (iscrt) score++; } string script = "alert('Score: " + score.ToString() + "');"; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "script", script, true); script = "alert('Your Teacher Will Receive the score');window.location='StudentHome'"; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "script2", script, true); }