public async Task <IHttpActionResult> Post(EnrollmentDTO enrollmentDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // status code 400 } //var course = new CourseDTO //{ // CourseId = courseDTO.CourseId, // Title = courseDTO.Title, // Credits = courseDTO.Credits //}; //Ctrl + K + S Redondear el codigo try { var enrollment = mapper.Map <Enrollment>(enrollmentDTO); //var course = mapper.Map<Course>(courseDTO); //course = await courseService.Insert(course); //return Ok(courseDTO); //Sastus code 400 enrollment = await enrollmentService.Insert(enrollment); return(Ok(enrollmentDTO)); //Sastus code 200 } catch (Exception ex) { return(InternalServerError(ex)); //Status code 500 } }
public async Task <IHttpActionResult> Post(EnrollmentDTO enrollmentDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState));//status code 400 } //var enrollment = new EnrollmentDTO //{ // EnrollmentID = enrollmentDTO.EnrollmentID, // CourseID = enrollmentDTO.CourseID, // StudentID = enrollmentDTO.StudentID, // Grade = enrollmentDTO.Grade //}; try { var enrollment = mapper.Map <Enrollment>(enrollmentDTO); enrollment = await enrollmentService.Insert(enrollment); return(Ok(enrollmentDTO));//status code 200 } catch (Exception ex) { return(InternalServerError(ex));//status code 500 } }
public async Task <IHttpActionResult> Insert(EnrollmentRequestDTO enrollmentDTO)//se devuelve un modelo { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var enrollment = _mapper.Map <Enrollment>(enrollmentDTO); enrollment = await enrollmentService.Insert(enrollment); return(Ok(enrollment)); } catch (Exception ex) { return(InternalServerError(ex)); } }