Exemplo n.º 1
0
        public async Task <IActionResult> Put(int palestranteId, PalestranteVm model)
        {
            try
            {
                var palestrante = await _repo.GetPalestranteAsyncById(palestranteId);

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

                _mapper.Map(model, palestrante);

                _repo.Add(palestrante);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/Palestrantes/{model.Id}", _mapper.Map <PalestranteVm>(palestrante)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post(PalestranteVm model)
        {
            try
            {
                var palestrante = _mapper.Map <Palestrante>(model);
                _repo.Add(palestrante);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/palestrantes/{model.Id}", _mapper.Map <PalestranteVm>(palestrante)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }