public ActionResult UpdateSnippet(int id, SnippetUpdateDto snippetToUpdate)
        {
            var snippetModelFromRepo = _snippetsRepo.GetSnippetById(id);

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

            _mapper.Map(snippetToUpdate, snippetModelFromRepo);

            //_apiRepo.UpdateCommand(cmdModelFromRepo);

            _snippetsRepo.SaveSnippetsChanges();

            // Return 204 (No Content)
            //return NoContent();
            var cmd = new SnippetReadDto {
                Id          = id,
                HowTo       = snippetToUpdate.HowTo,
                CodeSnippet = snippetToUpdate.CodeSnippet,
                Platform    = snippetToUpdate.Platform
            };

            // Return updated Resource
            return(Ok(_mapper.Map <SnippetReadDto>(cmd)));
        }
示例#2
0
        public ActionResult UpdateSnippet(int id, SnippetUpdateDto updateDto)
        {
            var objModel = _repository.GetSnippetById(id);

            if (objModel == null)
            {
                return(NotFound());
            }
            _mapper.Map(updateDto, objModel);
            _repository.UpdateSnippet(objModel);
            _repository.SaveChanges();
            return(NoContent());
        }