public TeacherEvaluationPaperResult(DateTime submitTimestamp, User evaluatedBy, StudentSubmitExaminationPaper studentSubmitExaminationPaper, double score) { SubmitTimestamp = submitTimestamp; EvaluatedBy = evaluatedBy; StudentSubmitExaminationPaper = studentSubmitExaminationPaper; Score = score; }
public async Task <StudentSubmitExaminationPaper> SubmitStudentPaper(StudentSubmitExaminationPaper studentSubmitExaminationPaper) { StudentSubmitExaminationPaper submittedPaperDeserialize = null; HttpResponseMessage responseMessage; string examinationEventSerialized = JsonSerializer.Serialize(studentSubmitExaminationPaper); Console.WriteLine(examinationEventSerialized); var content = new StringContent(examinationEventSerialized, Encoding.UTF8, "application/json"); // 1. Send POST request try { responseMessage = await client.PostAsync(uri + "/examinationevent/submitStudentExaminationPaper", 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(); submittedPaperDeserialize = JsonSerializer.Deserialize <StudentSubmitExaminationPaper>(readAsStringAsync); } else if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new Exception(serverMessage); } else if (responseMessage.StatusCode == HttpStatusCode.BadRequest) { throw new Exception(serverMessage); } return(submittedPaperDeserialize); }
public async Task <StudentSubmitExaminationPaper> GetStudentSubmittedPaper(int studentId, string examId) { StudentSubmitExaminationPaper studentExamPaper = null; HttpResponseMessage responseMessage; // 1. Send GET request try { responseMessage = await client.GetAsync($"{uri}/examinationevent/getStudentSubmittedPaper/{studentId}/{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(); studentExamPaper = JsonSerializer.Deserialize <StudentSubmitExaminationPaper>(readAsStringAsync); } else if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new Exception(serverMessage); } return(studentExamPaper); }