/// <inheritdoc />
        public TModel Update(long id, TUpdateModel updateModel)
        {
            var entity = _readRepository.Get(id);      //get entity
            var model  = _mapper.Map <TModel>(entity); //map to model

            _mapper.Map(updateModel, model);           //update model
            if (_validator.ValidateUpdate)
            {
                var prevModel  = _mapper.Map <TModel>(model); //clone model
                var validation = _validator.ValidateForUpdate(prevModel, model);
                if (validation != null)
                {
                    throw new BusinessModelValidationException(validation);
                }
            }
            _mapper.Map(model, entity); //update entity with updated model
            var newEntity = _writeRepository.Update(entity);

            _writeRepository.SaveChanges();
            var result = _mapper.Map <TModel>(newEntity);

            return(result);
        }
        /// <inheritdoc />
        public TModel Patch(int id, JsonPatchDocument <TUpdateModel> updateDocument)
        {
            var entity        = _readRepository.Get(id);
            var model         = _mapper.Map <TModel>(entity);
            var patchDocument = _mapper.Map <JsonPatchDocument <TModel> >(updateDocument);

            patchDocument.ApplyTo(model);
            if (_validator.ValidateUpdate)
            {
                var prevModel  = _mapper.Map <TModel>(entity);
                var validation = _validator.ValidateForUpdate(prevModel, model);
                if (validation != null)
                {
                    throw new BusinessModelValidationException(validation);
                }
            }
            _mapper.Map(model, entity);
            var newEntity = _writeRepository.Update(entity);

            _writeRepository.SaveChanges();
            var newModel = _mapper.Map <TModel>(newEntity);

            return(newModel);
        }