public IActionResult Add(RatingModel model) { if (ModelState.IsValid) { using (var db = new DB()) { var student = StudentManager.GetAll().FirstOrDefault(c => c.Name == model.StudentName && c.Surname == model.StudentSurname); var course = CourseManager.GetAll().FirstOrDefault(c => c.Course == model.CourseName); if (student != null && course != null) { RatingManager.Add(model.StudentName, model.StudentSurname, model.CourseName, model.Rating, model.Description); return(RedirectToAction(nameof(Index))); } else if (student == null) { ModelState.AddModelError("student", "Student not found!"); } else if (course == null) { ModelState.AddModelError("course", "Course not found!"); } } } return(View(model)); }