Exemple #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));
            }
        }
Exemple #2
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                PlataformaRepository rep = new PlataformaRepository();
                Plataforma           p   = rep.FindById(id);

                if (p != null)
                {
                    rep.Delete(p);

                    return(Request.CreateResponse(HttpStatusCode.OK, "Plataforma excluída com sucesso."));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Plataforma não localizada."));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Erro de servidor: " + e.Message));
            }
        }