Example #1
0
        public IActionResult Put(int id, [FromBody] Models.Request.AlbumDto albumRequest)
        {
            var album     = MapearDtoParaDominio(albumRequest);
            var mensagens = albumService.Validar(album);

            if (mensagens.Count > 0)
            {
                return(BadRequest(mensagens));
            }

            albumRepository.AtualizarAlbum(id, album);
            return(Ok());
        }
        public IActionResult Put(int id, [FromBody] Models.Request.AlbumDto albumRequest)
        {
            var albumTest = albumRepository.Obter(id);

            if (albumTest == null)
            {
                return(NotFound("Não existe album com esse id"));
            }

            var album     = MapearDtoParaDominio(albumRequest);
            var mensagens = albumService.Validar(album);

            if (mensagens.Count > 0)
            {
                return(BadRequest(mensagens));
            }

            albumRepository.AtualizarAlbum(id, album);
            database.Commit();
            return(Ok());
        }
        public IActionResult Put(int id, [FromBody] Models.Request.AlbumDto albumRequest)
        {
            var album = albumRepository.Obter(id);

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

            var albumParaAlterar = MapearDtoParaDominio(albumRequest);

            var mensagens = albumService.Validar(albumParaAlterar);

            if (mensagens.Count > 0)
            {
                return(BadRequest(mensagens));
            }

            var albumCadastrado = albumRepository.AtualizarAlbum(id, albumParaAlterar);

            contexto.SaveChanges();

            return(Ok(albumCadastrado));
        }