Exemplo n.º 1
0
        [Route("consultar")] //URL: /api/cliente/consultar
        public HttpResponseMessage GetAll()
        {
            try
            {
                //lista da classe de modelo
                List <ClienteModelConsulta> lista    = new List <ClienteModelConsulta>();
                ClienteBusiness             business = new ClienteBusiness();

                foreach (Cliente c in business.Consultar())
                {
                    ClienteModelConsulta model = new ClienteModelConsulta();
                    model.IdCliente    = c.IdCliente;
                    model.Nome         = c.Nome;
                    model.Email        = c.Email;
                    model.DataCadastro = c.DataCadastro;

                    lista.Add(model); //adicionar na lista
                }

                return(Request.CreateResponse(HttpStatusCode.OK, lista));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, " " +
                                              "Error: " + e.Message));;
            }
        }
Exemplo n.º 2
0
        // GET: Cliente/Consulta
        public ActionResult Consulta()
        {
            try
            {
                List <ClienteModelConsulta> lista = new List <ClienteModelConsulta>();
                ClienteRepositorio          rep   = new ClienteRepositorio();

                foreach (Cliente c in rep.ListarTodos())
                {
                    ClienteModelConsulta model = new ClienteModelConsulta();

                    model.IdCliente    = c.IdCliente;
                    model.Nome         = c.Nome;
                    model.Email        = c.Email;
                    model.DataCadastro = c.DataCadastro;

                    lista.Add(model);
                }
                ViewBag.Dados = lista;
            }
            catch (Exception e)
            {
                ViewBag.Mensagem = e.Message;
            }
            return(View());
        }
Exemplo n.º 3
0
        [Route("obter")] //URL: /api/cliente/obter?id={0}
        public HttpResponseMessage Get(int id)
        {
            try
            {
                ClienteBusiness      business = new ClienteBusiness();
                ClienteModelConsulta model    = new ClienteModelConsulta();
                Cliente c = business.ObterPorId(id);

                model.IdCliente    = c.IdCliente;
                model.Nome         = c.Nome;
                model.Email        = c.Email;
                model.DataCadastro = c.DataCadastro;

                return(Request.CreateResponse(HttpStatusCode.OK, model));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "" +
                                              "Erro: " + e.Message));
            }
        }