Esempio n. 1
0
        public async Task <IActionResult> Put(int SelecaoId, SelecaoDto model)
        {
            try
            {
                var selecao = await _repo.GetAllSelecaoAssyncById(SelecaoId);

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

                _mapper.Map(model, selecao);
                _repo.Update(selecao);

                if (await _repo.SaveChangesAssync())
                {
                    return(Created($"/api/selecao/{selecao.Id}", _mapper.Map <SelecaoDto>(selecao)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(BadRequest());
        }
Esempio n. 2
0
        public async Task <IActionResult> Post(SelecaoDto model)
        {
            try
            {
                var selecao = _mapper.Map <Selecao>(model);
                _repo.Add(selecao);

                if (await _repo.SaveChangesAssync())
                {
                    return(Created($"/api/selecao/{selecao.Id}", _mapper.Map <SelecaoDto>(selecao)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(BadRequest());
        }