Beispiel #1
0
        public IActionResult CreateStudent(int schoolId, [FromBody] PersonDTO personDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Student student = new Student()
            {
                Name         = personDTO.Name,
                BirthDate    = personDTO.BirthDate,
                Photo        = personDTO.Photo,
                AccessRights = personDTO.AccessRights
            };

            _schoolRepository.AddStudent(student, schoolId);
            return(CreatedAtRoute("GetStudent", new { schoolId, studentId = student.Id }, student));
        }
Beispiel #2
0
        public IActionResult CreateStudent(int schoolId, [FromBody] PersonDTO personDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int     maxStudentId = _schoolRepository.GetSchool(schoolId).StudentsList.Max(s => s.Id);
            Student student      = new Student()
            {
                Id           = ++maxStudentId,
                Name         = personDTO.Name,
                BirthDate    = personDTO.BirthDate,
                AccessRights = personDTO.AccessRights
            };

            _schoolRepository.AddStudent(student, schoolId);
            return(CreatedAtRoute("GetStudent", new { schoolId, studentId = student.Id }, student));
        }
 public async Task <Student> AddStudent(Student student)
 {
     return(await SchoolRepository.AddStudent(student));
 }