public IActionResult CreateCatalogueStudent(int schoolId, int catalogueId, [FromBody] CataloguePersonDTO cataloguePersonDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Student student = _schoolRepository.GetStudent(cataloguePersonDTO.Id, schoolId); List <Catalogue> catalogues = (List <Catalogue>)_schoolRepository.GetAllCatalogues(schoolId); foreach (Catalogue catalogue in catalogues) { foreach (Student stud in catalogue.Students) { if (stud.Id == student.Id) { return(Conflict(student.Name)); } } } _schoolRepository.AddCatalogueStudent(student, schoolId, catalogueId); return(CreatedAtRoute("GetCatalogueStudent", new { schoolId, catalogueId, studentId = student.Id }, student)); }