public async Task <IEnumerable <StudentFaceAttendance> > GetStudentFaceAttendances(string image, Section section) { int Count = 0; List <StudentFaceAttendance> studentFaceAttendances = new List <StudentFaceAttendance>(); List <Person> people = new List <Person>(); try { var identifyResults = await _faceService.IdentifyStudents(image); if (identifyResults.Count() > 0) { foreach (var identifyResult in identifyResults) { Person person = await _faceService.FaceClient().PersonGroupPerson.GetAsync(_faceService.GroupId(), identifyResult.Candidates[0].PersonId); people.Add(person); Console.WriteLine($"Person '{person.Name}' is identified for face in: {image} - {identifyResult.FaceId}," + $" confidence: {identifyResult.Candidates[0].Confidence}."); studentFaceAttendances.Add(new StudentFaceAttendance { Matric = long.Parse(person.Name.Trim()), ConfidanceLevel = Convert.ToInt32((identifyResult.Candidates[0].Confidence) * 100), }); } var identifyEmo = await _faceService.DetectFaceExtract(image); foreach (var emotion in identifyEmo) { try { studentFaceAttendances.ElementAt(Count).EmotionType = GetEmotion(emotion); } catch { Console.WriteLine("Array out of bound here"); } Count++; } var regiStudents = await _courseServices.GetCourseStudentsBySection(section); //foreach (var stu in regiStudents) { // studentFaceAttendances.Add(new StudentFaceAttendance // { // Matric = stu.Student.Matric, // EmotionType = EmotionType.Neutral, // AttendanceType = AttendanceType.Present, // ConfidanceLevel = 90, // }); //} foreach (var stu in regiStudents) { var stud = studentFaceAttendances.Find(st => st.Matric == stu.Student.Matric); if (stud != null) { studentFaceAttendances.Remove(stud); stud.AttendanceType = AttendanceType.Present; stud.EmotionType = EmotionType.Neutral; studentFaceAttendances.Add(stud); } else { studentFaceAttendances.Add(new StudentFaceAttendance { Matric = stu.Student.Matric, EmotionType = EmotionType.Undetected, AttendanceType = AttendanceType.Undetected, ConfidanceLevel = 0, }); } } } } catch { return(studentFaceAttendances); } return(studentFaceAttendances); }