Exemplo n.º 1
0
        public ActionResult UpdatePlatform(int id, JsonPatchDocument <PlatformUpdateDto> patchDoc)
        {
            try
            {
                //Validations
                var platform = _repository.GetPlatformById(id);
                if (platform == null)
                {
                    return(NotFound());
                }

                //Mapper
                var platformToPatch = _mapper.Map <PlatformUpdateDto>(platform);
                patchDoc.ApplyTo(platformToPatch, ModelState);

                //Validate model to patch
                if (!TryValidateModel(platformToPatch))
                {
                    return(ValidationProblem(ModelState));
                }

                _mapper.Map(platformToPatch, platform);
                _repository.UpdatePlatform(platform);
                _repository.SaveChanges();

                return(Ok());
            }
            catch (System.Exception)
            {
                return(NotFound());
            }
        }