public async Task AddRecord() { try { Lessons = Lessons.Substring(0, Lessons.Length - 2); var record = new CreateRecord { Teacher = Teacher, Room = Room, Note = Note, ClassNumber = SelectedNumber, ClassLetter = SelectedLetter, Lessons = Lessons, Date = Date }; await _recordTempService.PostRecord(record); ResetFields(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private async void MainPage_Load(object sender, EventArgs e) { var clientId = new HttpClient(); HttpResponseMessage responseId = await clientId.GetAsync("http://localhost:43719/api/member/Iduser/" + Mail + "/Idpassword/" + Password); string stringId = await responseId.Content.ReadAsStringAsync(); int lecturerId = int.Parse(stringId); string Lessons; List <string> LessonsList; var clientRole = new HttpClient(); HttpResponseMessage responseRole = await clientRole.GetAsync("http://localhost:43719/api/memberRole/lecturerId/" + lecturerId); string strRole = await responseRole.Content.ReadAsStringAsync(); string role = strRole.Substring(1, strRole.Length - 2); if (role == "h") { ContinueLecturer.Visible = true; } DateTime date = DateTime.Now; dateOnly = date.ToString(); dateOnly = dateOnly.Substring(0, 10); dateOnly = dateOnly.Replace('/', '-'); hourOnly = date.ToString(); hourOnly = hourOnly.Substring(11); try { var clientcheck = new HttpClient(); HttpResponseMessage responseCkeck = await clientcheck.GetAsync("http://localhost:43719/api/course/LectureId/" + lecturerId + "/dateOnly/" + dateOnly + "/hourOnly/" + hourOnly); string strCheck = await responseCkeck.Content.ReadAsStringAsync(); int courseId = int.Parse(strCheck); if (courseId != 0) { var clientCurrent = new HttpClient(); HttpResponseMessage responseCurrent = await clientCurrent.GetAsync("http://localhost:43719/api/course/courseId/" + courseId + "/id/" + lecturerId); string strCurrent = await responseCurrent.Content.ReadAsStringAsync(); if (responseCurrent.IsSuccessStatusCode) { Current.Text = "Current Course is: " + strCurrent.Substring(1, strCurrent.Length - 2); } var clientCourseStudents = new HttpClient(); HttpResponseMessage responseCourseStudents = await clientCourseStudents.GetAsync("http://localhost:43719/api/courseStudent/courseId/" + courseId); string strCourseStudents = await responseCourseStudents.Content.ReadAsStringAsync(); List <string> studentsIds = new List <string>(); studentsIds = ((strCourseStudents.Substring(1, strCourseStudents.Length - 2).Split(',')).ToList <string>()); foreach (var item in studentsIds) { string strStudentId = item.ToString().Substring(1, item.Length - 2); int studentId = int.Parse(strStudentId); var clientstudentDetails = new HttpClient(); HttpResponseMessage responsestudentDetails = await clientstudentDetails.GetAsync("http://localhost:43719/api/member/studentId/" + studentId); string strStudentDetails = await responsestudentDetails.Content.ReadAsStringAsync(); string studentDetails = strStudentDetails.Substring(1, strStudentDetails.Length - 2); ListCurrentStudents.Items.Add(studentDetails); } AttendedStudents(); } var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); HttpResponseMessage response = await client.GetAsync( "http://localhost:43719/api/App/id/" + lecturerId); HttpContent responseContent = response.Content; using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync())) { Lessons = (await reader.ReadToEndAsync()); LessonsList = ((Lessons.Substring(1, Lessons.Length - 2).Split(',')).ToList <string>()); foreach (var item in LessonsList) { int index = item.IndexOf(' '); string courseName = item.Substring(index, item.Length - 1 - index); if (courseName == "") { throw new Exception(); } courseList.Items.Add(courseName); } } } catch { MessageBox.Show("You have no courses"); } }