public async Task <TeacherEvaluationPaperResult> SubmitEvaluatedStudentPaperByTeacher( TeacherEvaluationPaperResult teacherEvaluationPaperResult) { TeacherEvaluationPaperResult submittedTeacherEvaluationPaperResultDeserialize = null; HttpResponseMessage responseMessage; string examinationEventSerialized = JsonSerializer.Serialize(teacherEvaluationPaperResult); Console.WriteLine(examinationEventSerialized); var content = new StringContent(examinationEventSerialized, Encoding.UTF8, "application/json"); // 1. Send POST request try { responseMessage = await client.PostAsync(uri + "/examinationevent/submitEvaluatedStudentPaper", content); // 2. Check if the resource was found, else throw exception to the client if (responseMessage.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Ooops, resource not found"); } } // 3. Catch the exception in case the Server is not running catch (HttpRequestException e) { throw new Exception("No connection could be made because the server is not responding"); } string serverMessage = responseMessage.Content.ReadAsStringAsync().Result; // 4. Check the response status codes, else throws the error message to the client if (responseMessage.IsSuccessStatusCode) { // 5. Deserialize the object string readAsStringAsync = await responseMessage.Content.ReadAsStringAsync(); submittedTeacherEvaluationPaperResultDeserialize = JsonSerializer.Deserialize <TeacherEvaluationPaperResult>(readAsStringAsync); } else if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new Exception(serverMessage); } else if (responseMessage.StatusCode == HttpStatusCode.BadRequest) { throw new Exception(serverMessage); } return(submittedTeacherEvaluationPaperResultDeserialize); }
public async Task <TeacherEvaluationPaperResult> GetExaminationEventResultByExamIdAndStudentId(long currentUserId, long examId) { TeacherEvaluationPaperResult studentExamPaperResult = null; HttpResponseMessage responseMessage; // 1. Send GET request try { responseMessage = await client.GetAsync($"{uri}/examinationevent/getExaminationEventResultByExamIdAndStudentId/{currentUserId}/{examId}"); // 2. Check if the resource was found, else throw exception to the client if (responseMessage.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Ooops, resource not found"); } } // 3. Catch the exception in case the Server is not running catch (HttpRequestException e) { throw new Exception("No connection could be made because the server is not responding"); } string serverMessage = responseMessage.Content.ReadAsStringAsync().Result; // 4. Check the response status codes, else throws the error message to the client if (responseMessage.IsSuccessStatusCode) { // 5. Deserialize the object string readAsStringAsync = await responseMessage.Content.ReadAsStringAsync(); studentExamPaperResult = JsonSerializer.Deserialize <TeacherEvaluationPaperResult>(readAsStringAsync); } else if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new Exception(serverMessage); } return(studentExamPaperResult); }