Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] InstructorDto instructor)
        {
            if (instructor == null)
            {
                return(BadRequest());
            }

            Instructor instructorToSave = Mapper.Map <Instructor>(instructor);

            if (!await InstructorRepository.SaveAsync(instructorToSave))
            {
                throw new Exception("Creating a instructor failed on save.");
            }

            InstructorDto instructorToReturn = Mapper.Map <InstructorDto>(instructorToSave);

            return(CreatedAtRoute("GetInstructor", new { id = instructorToReturn.Id }, instructorToReturn));
        }