public async Task <IHttpActionResult> Post(OfficeAssignmentDTO officeAssignmentDTO)
        {
            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 officeAssignment = mapper.Map <OfficeAssignment>(officeAssignmentDTO);

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

                officeAssignment = await officeAssignmentService.Insert(officeAssignment);

                return(Ok(officeAssignmentDTO)); //Sastus code 200
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex)); //Status code 500
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> Post(OfficeAssignmentDTO OfficeAssignmentDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var officeassignment = mapper.Map <OfficeAssignment>(OfficeAssignmentDTO);
                officeassignment = await officeassignmentService.Insert(officeassignment);

                return(Ok(officeassignment));
            }
            catch (Exception ex) { return(InternalServerError(ex)); }
        }
Exemple #3
0
        public async Task <ActionResult> Create(OfficeAssignmentDTO officeAssignmentDTO)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            var instructors       = await instructorService.GetAll();

            var instructorsDTO = instructors.Select(x => mapper.Map <InstructorDTO>(x));

            ViewData["Instructors"] = new SelectList(instructorsDTO, "ID", "FullName", officeAssignmentDTO.InstructorID);

            if (ModelState.IsValid)
            {
                var officeAssignmentService = new OfficeAssignmentService(new OfficeAssignmentRepository(UniversityContext));
                var officeAssignment        = mapper.Map <OfficeAssignment>(officeAssignmentDTO);
                officeAssignment = await officeAssignmentService.Insert(officeAssignment);

                return(RedirectToAction("Index", "OfficeAssignments"));
            }

            return(View(officeAssignmentDTO));
        }