public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var palestrante = await repo.GetPalestrantesAsyncById(id, false);

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

                repo.Delete(palestrante);

                if (await repo.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou!"));;
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var evento = (await _repository.GetListFilterAsync(e => e.Id == id)).FirstOrDefault();
                if (evento == null)
                {
                    return(NotFound("Evento não localizado"));
                }

                _repository.Delete(evento);
                await _repository.SaveChangesAsync();

                return(Ok());
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Erro interno"));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(int EventoId)
        {
            try{
                var evento = await _repo.GetALLEventoAsincById(EventoId, false);

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

                _repo.Delete(evento);
                if (await _repo.SaveChngesAsync())
                {
                    return(Ok());
                }
            }catch (System.Exception) {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no banco de dados"));
            }

            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Delete(int EventoId)
        {
            try
            {
                // Verifica se encontra algum elemento.
                // Aqui eliminamos que seja feito algum Join no banco de dados com Eventos com Palestrantes
                // procuramos saber somente se o evento foi encontrado.
                var evento = await _repo.GetAllEventoAsyncById(EventoId, false);

                // Se não foi encontrado elemento não é excludido.
                if (evento == null)
                {
                    return(NotFound());
                }

                // Caso encontre o elemento segue o código ↓

                // Na exclusão do model ele não precisa ser assincrono.
                // Aqui ele muda um estado do EntityFramework.
                _repo.Delete(evento);

                // Na hora de salvar ele precisa ser assincrono (await).
                // Aqui ele salva toda a mudança de estado.
                if (await _repo.SaveChangeAsync())
                {
                    // Aqui utilizamos o status code 201 que foi salvo com sucesso.
                    return(Ok());
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }

            // Caso não tenha dado certo o SaveChangeAsync retorna a mensagem de erro BadRequest.
            return(BadRequest());
        }