public IActionResult CreateMentor(int schoolId, [FromBody] PersonDTO personDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Mentor mentor = new Mentor()
            {
                Name         = personDTO.Name,
                Photo        = personDTO.Photo,
                BirthDate    = personDTO.BirthDate,
                AccessRights = personDTO.AccessRights
            };

            _schoolRepository.AddMentor(mentor, schoolId);
            return(CreatedAtRoute("GetMentor", new { schoolId, mentorId = mentor.Id }, mentor));
        }
示例#2
0
        public IActionResult CreateMentor(int schoolId, [FromBody] PersonDTO personDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int    maxMentorId = _schoolRepository.GetSchool(schoolId).MentorsList.Max(m => m.Id);
            Mentor mentor      = new Mentor()
            {
                Id           = ++maxMentorId,
                Name         = personDTO.Name,
                BirthDate    = personDTO.BirthDate,
                AccessRights = personDTO.AccessRights
            };

            _schoolRepository.AddMentor(mentor, schoolId);
            return(CreatedAtRoute("GetMentor", new { schoolId, mentorId = mentor.Id }, mentor));
        }