public IActionResult Index() { var students = _repository.GetStudents(); var dataForView = new List <StudentViewModel>(); foreach (var st in students) { var vm = new StudentViewModel(); vm.IdStudent = st.IdStudent; vm.FirstName = st.FirstName; vm.LastName = st.LastName; vm.Address = st.Address; var grades = _repository.GetGrades(st.IdStudent); foreach (var g in grades) { if (g.SubjectType == "Group 1") { vm.EctsSum += 5; } else if (g.Subject == "Group 2") { vm.EctsSum += 3; } else if (g.SubjectType == "Group 3") { vm.EctsSum += 1; } vm.AverageGrade += g.GradeValue; } if (grades.Count() > 0) { vm.AverageGrade = vm.AverageGrade / grades.Count(); } dataForView.Add(vm); } return(View(dataForView)); }