Beispiel #1
0
        // PUT api/tanques
        public HttpResponseMessage Put([FromBody] Tanque tanque)
        {
            try
            {
                Tanque localizado = TanqueRepository.GetTanque(tanque.Deposito);

                if (localizado == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                TanqueRepository.UpdateTanque(tanque);

                Tanque alterado = TanqueRepository.GetTanque(tanque.Deposito);

                if (alterado == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, alterado));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Beispiel #2
0
        // DELETE api/tanques/{deposito}
        public HttpResponseMessage Delete(string id)
        {
            try
            {
                var tanque = TanqueRepository.GetTanque(id);

                if (tanque == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                TanqueRepository.DeleteTanque(id);
                var deletado = TanqueRepository.GetTanque(id);

                if (deletado == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NoContent));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Beispiel #3
0
        // GET api/tanques/{deposito}
        public HttpResponseMessage Get(string id)
        {
            try
            {
                var tanque = TanqueRepository.GetTanque(id);

                if (tanque == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, tanque));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Beispiel #4
0
        // GET api/tanques
        public HttpResponseMessage GetAll()
        {
            try
            {
                var tanques = TanqueRepository.GetTanques();

                if (tanques.Count == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.NoContent));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, tanques));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Beispiel #5
0
        // POST api/tanques
        public HttpResponseMessage Post([FromBody] Tanque tanque)
        {
            try
            {
                TanqueRepository.SaveTanque(tanque);
                var inserido = TanqueRepository.GetTanque(tanque.Deposito);

                if (inserido == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }

                return(Request.CreateResponse(HttpStatusCode.Created, tanque));
            }
            catch (Exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }