Esempio n. 1
0
 public async Task <ActionResult> Post(Evento model)
 {
     try
     {
         _repo.Add(model);
         if (await _repo.SaveChangesAsync())
         {
             return(Created($"api/evento/{model.Id}", model));
         }
     }
     catch (System.Exception ex)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Erro no banco de dados, erro: {ex.Message}"));
     }
     return(BadRequest());
 }
Esempio n. 2
0
        public async Task <IActionResult> Post(Evento model)
        {
            try
            {
                _repo.Add(model);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/evento/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco Dados Falhou"));
            }

            return(BadRequest());
        }
Esempio n. 3
0
        public async Task <IActionResult> Post(EventoDto model)

        {
            try
            {
                var evento = _mapper.Map <Evento>(model);
                _repo.Add(evento);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/eventos/{model.id}", _mapper.Map <EventoDto>(evento)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Falha ao conectar com a base de dados, tente novamente mais tarde {ex.Message}"));
            }
            return(BadRequest());
        }