Exemplo n.º 1
0
        public IActionResult CreateUni(int universityId, [FromBody] StudentDto studentDto)
        {
            var university = _db.Universities.SingleOrDefault(u => u.UniversityId == universityId);

            if (university == null)
            {
                return(BadRequest("University not found!"));
            }

            var student = studentDto.ToDb();

            if (student == null)
            {
                return(BadRequest("Invalid student!"));
            }

            student.University = university;

            _db.Students.Add(student);
            _db.SaveChanges();
            return(Ok());
        }