Example #1
0
        public async Task <IHttpActionResult> Put(CourseInstructorDTO courseInstructorDTO, int id) // object - cuerpo pero si es prmitivo por la url
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // status code 400
            }
            if (courseInstructorDTO.InstructorID != id)
            {
                return(BadRequest());
            }

            var flag = await courseInstructorService.GetById(id);

            if (flag == null)
            {
                return(NotFound()); // status code 404
            }
            try
            {
                var courseInstructor = mapper.Map <CourseInstructor>(courseInstructorDTO);
                courseInstructor = await courseInstructorService.Insert(courseInstructor);

                return(Ok(courseInstructor)); //Sastus code 200
                //return Ok(courseDTO); //Sastus code 200
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex)); //Status code 500
            }
        }
Example #2
0
        public async Task <IHttpActionResult> Put(CourseInstructorDTO courseInstructorDTO, int id)//objet=> body/primitivo => url
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));//status code 400
            }
            if (courseInstructorDTO.ID != id)
            {
                return(BadRequest());
            }

            var flag = await courseInstructorService.GetById(id);

            if (flag == null)
            {
                return(NotFound());//status code 404
            }
            try
            {
                var courseInstructor = mapper.Map <CourseInstructor>(courseInstructorDTO);
                courseInstructor = await courseInstructorService.Update(courseInstructor);

                return(Ok(courseInstructorDTO));//status code 200
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));//status code 500
            }
        }
Example #3
0
        public async Task <IHttpActionResult> Post(CourseInstructorDTO courseInstructorDTO)
        {
            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 courseInstructor = mapper.Map <CourseInstructor>(courseInstructorDTO);

                //var course = mapper.Map<Course>(courseDTO);
                //course = await courseService.Insert(course);
                //return Ok(courseDTO); //Sastus code 400

                courseInstructor = await courseInstructorService.Insert(courseInstructor);

                return(Ok(courseInstructorDTO)); //Sastus code 200
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex)); //Status code 500
            }
        }
Example #4
0
        public async Task <IHttpActionResult> Post(CourseInstructorDTO courseInstrutorDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));//status code 400
            }
            //var courseInstrutor = new CourseInstructorDTO
            //{
            //    ID = coursesInstrutorsDTO.ID,
            //    CourseID = coursesInstrutorsDTO.CourseID,
            //    InstructorID = coursesInstrutorsDTO.InstructorID
            //};

            try
            {
                var courseInstrutor = mapper.Map <CourseInstructor>(courseInstrutorDTO);
                courseInstrutor = await courseInstructorService.Insert(courseInstrutor);

                return(Ok(courseInstrutorDTO));//status code 200
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));//status code 500
            }
        }