예제 #1
0
        public ActionResult PartialTeacherUpdate(int id, JsonPatchDocument <TeacherUpdateDto> patchDoc)
        {
            var TeacherModelFromRepo = _repo.GetTeacherById(id);

            if (TeacherModelFromRepo == null)
            {
                return(NotFound());
            }
            var TeacherToPatch = _mapper.Map <TeacherUpdateDto>(TeacherModelFromRepo);

            patchDoc.ApplyTo(TeacherToPatch, ModelState);
            if (!TryValidateModel(ModelState))
            {
                return(ValidationProblem(ModelState));
            }
            _mapper.Map(TeacherToPatch, TeacherModelFromRepo);
            _repo.UpdateTeacher(id, TeacherModelFromRepo);
            _repo.SaveChanges();
            return(NoContent());
        }