Esempio n. 1
0
        public async Task <IActionResult> Put(int Id, ProdutoDto model)
        {
            try
            {
                var produto = await _repo.GetAllProdutoAsyncById(Id, false);

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

                _mapper.Map(model, produto);

                _repo.Update(produto);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/produto/{model.Id}", _mapper.Map <ProdutoDto>(produto)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de Dados Falhou"));
            }

            return(BadRequest());
        }
Esempio n. 2
0
        public async Task <IActionResult> Put(int CategoriaId, CategoriaDto model)
        {
            try
            {
                var categoria = await _repo.GetAllPedidoAsyncById(CategoriaId, false);

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

                _mapper.Map(model, categoria);

                _repo.Update(categoria);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/categoria/{model.Id}", _mapper.Map <CategoriaDto>(categoria)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de Dados Falhou"));
            }

            return(BadRequest());
        }