Ejemplo n.º 1
0
        public IActionResult GetById(long id)
        {
            ResponseDto <Restaurante> response = new ResponseDto <Restaurante>();

            try
            {
                RestauranteBll bll         = new RestauranteBll(_context);
                Restaurante    restaurante = bll.GetById(id);

                response.Result = restaurante;
                response.Status = StatusResponse.SUCCESS.Value;
            }
            catch (EntityNotFoundException ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = "Erro ao consultar restaurante: " + ex.Message;
            }

            return(new ObjectResult(response));
        }
Ejemplo n.º 2
0
        public IActionResult GetAll()
        {
            ResponseDto <List <Restaurante> > response = new ResponseDto <List <Restaurante> >();

            try
            {
                RestauranteBll     bll          = new RestauranteBll(_context);
                List <Restaurante> restaurantes = bll.GetAll();

                response.Result = restaurantes;
                response.Status = StatusResponse.SUCCESS.Value;
            }
            catch (ListNoContentException ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = "Erro ao consultar todos os restaurantes: " + ex.Message;
            }

            return(new ObjectResult(response));
        }
Ejemplo n.º 3
0
        public IActionResult GetByNome(string nome)
        {
            ResponseDto <List <Restaurante> > response = new ResponseDto <List <Restaurante> >();

            try
            {
                RestauranteBll     bll          = new RestauranteBll(_context);
                List <Restaurante> restaurantes = bll.GetByNome(nome);

                response.Result = restaurantes;
                response.Status = StatusResponse.SUCCESS.Value;
            }
            catch (EntityNotFoundException ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = "Erro ao consultar restaurante: " + ex.Message;
            }

            return(new ObjectResult(response));
        }
Ejemplo n.º 4
0
        public IActionResult Delete(int id)
        {
            ResponseDto <bool> response = new ResponseDto <bool>();

            try
            {
                RestauranteBll bll = new RestauranteBll(_context);
                bll.Delete(id);
                response.Status = StatusResponse.SUCCESS.Value;
            }
            catch (Exception ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = "Erro ao excluir restaurante: " + ex.Message;
            }

            return(new ObjectResult(response));
        }
Ejemplo n.º 5
0
        public IActionResult Save([FromBody] Restaurante item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            ResponseDto <Restaurante> response = new ResponseDto <Restaurante>();

            try
            {
                RestauranteBll bll         = new RestauranteBll(_context);
                Restaurante    restaurante = bll.Save(item);

                return(GetById(restaurante.Id));
            }
            catch (Exception ex)
            {
                response.Status  = StatusResponse.ERROR.Value;
                response.Message = "Erro ao salvar o restaurante: " + ex.Message;
            }

            return(new ObjectResult(response));
        }