Пример #1
0
        public async Task <ActionResult> PatchSubject(Guid subjectId, [FromBody] JsonPatchDocument <SubjectToUpdate> patchDocument)
        {
            if (patchDocument == null)
            {
                return(BadRequest());
            }

            var subjectFromRepo = await _repository.GetSubjectAsync(subjectId);

            if (subjectFromRepo == null)
            {
                return(NotFound());
            }

            var subjectToPatch = _mapper.Map <SubjectToUpdate>(subjectFromRepo);

            patchDocument.ApplyTo(subjectToPatch, ModelState);
            if (!TryValidateModel(subjectToPatch))
            {
                return(ValidationProblem());
            }

            _mapper.Map(subjectToPatch, subjectFromRepo);

            _repository.UpdateSubject(subjectFromRepo);

            await _repository.SaveAsync();

            return(NoContent());
        }