Ejemplo n.º 1
0
        public EnrollmentViewModel Create(Enrollment entity)
        {
            _enrollmentRepository.Add(entity);
            var enrollment = _enrollmentRepository
                             .Get <Student>(
                e => e.StudentId == entity.StudentId
                );

            enrollment = _enrollmentRepository
                         .Get <Course>(
                e => e.CourseId == entity.CourseId
                );
            return(new EnrollmentViewModel()
            {
                Id = enrollment.Id,
                StudentId = enrollment.StudentId,
                CourseId = enrollment.CourseId,
                Student = enrollment.Student,
                Course = enrollment.Course
            });
        }
        public async Task <ActionResult <dynamic> > Post(
            [FromServices] EnrollmentRepository enrollmentRepository,
            [FromBody] EnrollmentRequest model
            )
        {
            if (ModelState.IsValid)
            {
                var enrollment = await enrollmentRepository.Add(model);

                if (enrollment == null)
                {
                    return(BadRequest(new { message = "Usuário ou curso estão incorretos" }));
                }

                return(enrollment);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }