예제 #1
0
        public ActionResult <Envelope> Get(int id)
        {
            Envelope envelope = new Envelope();

            try
            {
                // carregar e retornar um contato
                BusContato bContato = new BusContato();

                // retorno da API
                envelope.Colecao.Add(bContato.Carregar(id));
            }
            catch (Exception e)
            {
                envelope.AddExcecao("Erro ao CARREGAR contato", e);
            }
            return(Ok(envelope));
        }
예제 #2
0
        public ActionResult <IActionResult> Get()
        {
            Envelope envelope = new Envelope();

            try
            {
                // retornar a lista de contatos
                BusContato bContato = new BusContato();

                // retorno da API
                envelope.Colecao = bContato.Listar().ToList <object>();
            }
            catch (Exception e)
            {
                envelope.AddExcecao("Erro ao CARREGAR contato.", e);
            }
            return(Ok(envelope));
        }
예제 #3
0
        public ActionResult <IActionResult> Delete(int id)
        {
            Envelope envelope = new Envelope();

            try
            {
                // apagar
                BusContato bContato = new BusContato();
                bContato.Apagar(id);

                // retorno da API
                envelope.Infos.Add("Sucesso ao APAGAR contato");
            }
            catch (Exception e)
            {
                envelope.AddExcecao("Erro ao APAGAR contato", e);
            }
            return(Ok(envelope));
        }
예제 #4
0
        public ActionResult <IActionResult> Post([FromBody] Contato value)
        {
            Envelope envelope = new Envelope();

            try
            {
                // criar ou editar (salvar)
                BusContato bContato = new BusContato();
                bContato.Salvar(value);

                // retorno da API
                envelope.Infos.Add("Sucesso ao GRAVAR contato");

                // retorno o mesmo objeto para cliente poder ter campos atualizados (pk e idade);
                envelope.Colecao.Add(value);
            }
            catch (Exception e)
            {
                envelope.AddExcecao("Erro ao GRAVAR contato", e);
            }
            return(Ok(envelope));
        }