Example #1
0
        public HttpResponseMessage ConsultarPorId(int id)
        {
            try
            {
                PlataformaRepository rep = new PlataformaRepository();
                Plataforma           p   = rep.FindById(id);

                if (p != null)
                {
                    PlataformaConsultaViewModel model = new PlataformaConsultaViewModel();

                    model.IdPlataforma = p.IdPlataforma;
                    model.Nome         = p.Nome;
                    model.Modelo       = p.Modelo;

                    return(Request.CreateResponse(HttpStatusCode.OK, model));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Plataforma não localizada."));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
            }
        }
        public IActionResult Index()
        {
            IList <PlataformaConsultaViewModel> lista = new List <PlataformaConsultaViewModel>();

            foreach (var plataforma in repository.FindAll())
            {
                PlataformaConsultaViewModel model = new PlataformaConsultaViewModel();
                model.IdPlataforma = plataforma.IdPlataforma;
                model.Nome         = plataforma.Nome;

                lista.Add(model);
            }

            return(View(lista));
        }
Example #3
0
        public HttpResponseMessage Consultar()
        {
            try
            {
                List <PlataformaConsultaViewModel> lista = new List <PlataformaConsultaViewModel>();
                PlataformaRepository rep = new PlataformaRepository();

                foreach (Plataforma p in rep.FindAll())
                {
                    PlataformaConsultaViewModel model = new PlataformaConsultaViewModel();
                    model.IdPlataforma = p.IdPlataforma;
                    model.Nome         = p.Nome;
                    model.Modelo       = p.Modelo;

                    lista.Add(model);
                }

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